Skip to content

How to get the Left or Right value of Either<L, R> #1372

Answered by aloslider
juchom asked this question in Q&A
Discussion options

You must be logged in to vote
using LanguageExt;
using static LanguageExt.Prelude;

static int MyFunction(int i) =>
    InnerFunction(i).IfLeft(x => throw new Exception(x));

static Either<string, int> InnerFunction(int i) =>
    i % 2 == 0 // assuming error should be on mod 2?
    ? Left("this is an error")
    : Right(123);

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by juchom
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants