import { EitherAsync , sequence } from '..' ; import { Either } from '../Either' ; import { NonEmptyList } from '../NonEmptyList' ; import { pipe } from './function-utils' ; import { swap } from '../pointfree/swap' ; export const createValidator = < A , L , R > ( validator , ... validators ) => ( arg ) => { const results = [ validator , ... validators ] . map ( ( validator ) => validator ( arg ) . swap ( ) ) as NonEmptyList < Either < R , L > > ; return pipe ( results , sequence ( Either . of ) , swap ( ) ) ; } ; export const createAsyncValidator = < A , L , R > ( validator , ... validators ) => ( arg ) => { const results = [ validator , ... validators ] . map ( ( validator ) => validator ( arg ) . swap ( ) ) as NonEmptyList < EitherAsync < R , L > > ; return pipe ( results , sequence ( EitherAsync . of ) , swap ( ) ) ; } ;