// TODO(Mike/Max): naming conflict with Validation from runtime module /** * @tsplus type Validation */ export interface Validation extends HKT { readonly type: HKT.Kind } /** * @tsplus static DSL getValidationF */ export function getValidationF(M: Monad & Run & Fail & Applicative) { return (S: Associative): Applicative> => HKT.instance({ any: M.any, map: M.map, both: (fb: HKT.Kind) => (fa: HKT.Kind) => { const both = M.both(M.either(fb))(M.either(fa)) return M.flatten( M.map(([eitherA, eitherB]: readonly [Either, Either]) => eitherA.fold( (ea) => eitherB.fold( (eb) => M.fail(S.combine(ea, eb)), () => M.fail(ea) ), (a) => eitherB.fold( (e) => M.fail(e), (b) => DSL.succeedF(M)([a, b] as const) ) ) )(both) ) } }) }