Пример #1
0
 /// <summary>
 /// Mirrors left and right
 /// </summary>
 public static Either <right, left> Flip <left, right>(this Either <left, right> that) =>
 that.FlipHomo(that.Alg(), that.Alg().Flip());
Пример #2
0
 /// <summary>
 /// Ensure that contained value (if any) satisfies the predicate or else return Left
 /// Enumerable.Where-like filter
 /// </summary>
 public static Either <left, right> Filter <left, right>(this Either <left, right> that, Func <right, bool> p, SNeutral <left, Unit> neutral = null) => // todo resolve neutral
 that.Map(p).GetRightOr(false) ? that : that.Alg().InjectLeft((neutral ?? AObject <left> .Class).NullOp());
Пример #3
0
 /// <summary>
 /// Try to get right safely
 /// </summary>
 public static Opt <right> TryGetRight <left, right>(this Either <left, right> that) =>
 that.BiMap(that.Alg(), _ => Unit(), Id, AOpt <right> .Class);