public static Lst <EitherUnsafe <L, B> > Traverse <L, A, B>(this EitherUnsafe <L, Lst <A> > ma, Func <A, B> f) => ma.MatchUnsafe( Left: e => List(EitherUnsafe <L, B> .Left(e)), Right: xs => xs.Map(x => RightUnsafe <L, B>(f(x))));
public static Stck <EitherUnsafe <L, B> > Traverse <L, A, B>(this EitherUnsafe <L, Stck <A> > ma, Func <A, B> f) => ma.MatchUnsafe( Left: ex => Stack(EitherUnsafe <L, B> .Left(ex)), Right: xs => toStack(xs.Map(x => RightUnsafe <L, B>(f(x)))));
public static Que <EitherUnsafe <L, B> > Traverse <L, A, B>(this EitherUnsafe <L, Que <A> > ma, Func <A, B> f) => ma.MatchUnsafe( Left: ex => Queue(EitherUnsafe <L, B> .Left(ex)), Right: xs => new Que <EitherUnsafe <L, B> >(xs.Map(x => RightUnsafe <L, B>(f(x)))));
/// <summary> /// Invokes the Right or Left action depending on the state of the Either provided /// </summary> /// <typeparam name="L">Left</typeparam> /// <typeparam name="R">Right</typeparam> /// <param name="either">Either to match</param> /// <param name="Right">Action to invoke if in a Right state</param> /// <param name="Left">Action to invoke if in a Left state</param> /// <returns>Unit</returns> public static Unit matchUnsafe <L, R>(EitherUnsafe <L, R> either, Action <R> Right, Action <L> Left) => either.MatchUnsafe(Right, Left);
public static IEnumerable <EitherUnsafe <L, B> > Traverse <L, A, B>(this EitherUnsafe <L, IEnumerable <A> > ma, Func <A, B> f) => ma.MatchUnsafe( Left: e => new[] { LeftUnsafe <L, B>(e) }, Right: xs => xs.Map(x => RightUnsafe <L, B>(f(x))));
/// <summary> /// Invokes the Right or Left function depending on the state of the Either provided /// </summary> /// <typeparam name="L">Left</typeparam> /// <typeparam name="R">Right</typeparam> /// <typeparam name="Ret">Return type</typeparam> /// <param name="either">Either to match</param> /// <param name="Right">Function to invoke if in a Right state</param> /// <param name="Left">Function to invoke if in a Left state</param> /// <returns>The return value of the invoked function</returns> public static Ret matchUnsafe <L, R, Ret>(EitherUnsafe <L, R> either, Func <R, Ret> Right, Func <L, Ret> Left) => either.MatchUnsafe(Right, Left);
public static Arr <EitherUnsafe <L, B> > Traverse <L, A, B>(this EitherUnsafe <L, Arr <A> > ma, Func <A, B> f) => ma.MatchUnsafe( Left: e => Array(LeftUnsafe <L, B>(e)), Right: xs => xs.Map(x => RightUnsafe <L, B>(f(x))));
public Unit Left(Action <L> leftHandler) => either.MatchUnsafe(rightHandler, leftHandler);
public Ret Left(Func <L, Ret> left) => either.MatchUnsafe(rightHandler, left);
public static Identity <EitherUnsafe <L, B> > Traverse <L, A, B>(this EitherUnsafe <L, Identity <A> > ma, Func <A, B> f) => ma.MatchUnsafe( Right: x => new Identity <EitherUnsafe <L, B> >(f(x.Value)), Left: e => new Identity <EitherUnsafe <L, B> >(EitherUnsafe <L, B> .Left(e)));