// tracing: off import { _A, _E } from "@effect-ts/core/Effect" /** * @tsplus type ets/Schema/These * @tsplus companion ets/Schema/TheseOps */ export class These { readonly [_E]!: () => E readonly [_A]!: () => A constructor(readonly effect: Either]>) {} } export function succeed(a: A) { return new These(Either(tuple(a, Opt.none))) } export function warn(a: A, e: E) { return new These(Either(tuple(a, Opt(e)))) } export function fail(e: E) { return new These(Either.left(e)) } export function foldM_( self: These, onSuccess: (a: A) => These, onBoth: (a: A, e: E) => These, onFail: (e: E) => These ): These { return new These( self.effect.match( (x): Either]> => onFail(x).effect, ([result, warnings]) => warnings._tag === "None" ? onSuccess(result).effect : onBoth(result, warnings.value).effect ) ) } export function foldM( onSuccess: (a: A) => These, onBoth: (a: A, e: E) => These, onFail: (e: E) => These ) { return (self: These): These => foldM_(self, onSuccess, onBoth, onFail) } export function map_(self: These, f: (a: A0) => A) { return foldM_( self, a => succeed(f(a)), (a, e) => warn(f(a), e), fail ) } export function map(f: (a: A0) => A) { return (self: These) => map_(self, f) } export function mapError_(self: These, f: (a: E0) => E): These { return foldM_( self, a => succeed(a), (a, e) => warn(a, f(e)), e => fail(f(e)) ) } export function mapError( f: (a: E0) => E ): (self: These) => These { return self => mapError_(self, f) } export function chain_( self: These, f: (a: A0, w: Opt) => These ) { return foldM_( self, a => f(a, Opt.none), (a, _) => f(a, Opt(_)), fail ) } export function chain(f: (a: A0, w: Opt) => These) { return (self: These) => chain_(self, f) } export function result(self: These): Either]> { return self.effect }