Skip to content

Commit

Permalink
Apply supported for EitherRight
Browse files Browse the repository at this point in the history
This makes wrapping the function you're using in the application simpler.
  • Loading branch information
louthy committed Oct 1, 2023
1 parent 9f6e9cc commit bce0a16
Showing 1 changed file with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,22 @@ public static class EitherRightLeftExt
ma.Match(
r => Prelude.Left<L, C>(bind(r).Value),
l => Prelude.Left<L, C>(l));

public static EitherRight<B> Apply<A, B>(this EitherRight<Func<A, B>> mf, EitherRight<A> ma) =>
mf.Bind(f => ma.Map(a => f(a)));

public static EitherRight<Func<B, C>> Apply<A, B, C>(this EitherRight<Func<A, B, C>> mf, EitherRight<A> ma) =>
mf.Bind(f => ma.Map<Func<B, C>>(a => b => f(a, b)));

public static EitherRight<C> Apply<A, B, C>(this EitherRight<Func<A, B, C>> mf, EitherRight<A> ma, EitherRight<B> mb) =>
mf.Bind(f => ma.Bind(a => mb.Map(b => f(a, b))));

public static Either<L, B> Apply<L, A, B>(this EitherRight<Func<A, B>> mf, Either<L, A> ma) =>
mf.Bind(f => ma.Map(a => f(a)));

public static Either<L, Func<B, C>> Apply<L, A, B, C>(this EitherRight<Func<A, B, C>> mf, Either<L, A> ma) =>
mf.Bind(f => ma.Map<Func<B, C>>(a => b => f(a, b)));

public static Either<L, C> Apply<L, A, B, C>(this EitherRight<Func<A, B, C>> mf, Either<L, A> ma, Either<L, B> mb) =>
mf.Bind(f => ma.Bind(a => mb.Map(b => f(a, b))));
}

0 comments on commit bce0a16

Please sign in to comment.