Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Either usability improvements #1132

Merged
merged 1 commit into from
Jul 8, 2015
Merged

Conversation

kekekeks
Copy link
Contributor

@kekekeks kekekeks commented Jul 8, 2015

Construction
Before:

static Either<int, string> Foo(bool left)
{
    if (left)
        return new Left<int, string>(123);
    else
        return new Right<int, string>("321");
}

After (first variant is still supported):

static Either<int, string> Bar(bool left)
{
    if (left)
        return Either.Left(123);
    else
        return Either.Right("123");
}

Transformations

var either = new Left<int, string>(123);
return either.
    .MapLeft(x => x + 1)
    .MapRight(s => s.Substring(1))
    .Map(x => x + 2, s => s + "123")
    .Fold(x => x/2, s => s.Length);

@Aaronontheweb
Copy link
Member

@kekekeks what's the output of the transformation at the end here? :p

@kekekeks
Copy link
Contributor Author

kekekeks commented Jul 8, 2015

63
MapRight and the right part of Map do nothing, since its Left, so its (123+1+2)/2

@Aaronontheweb
Copy link
Member

Got it! awesome. Makes sense.

Aaronontheweb added a commit that referenced this pull request Jul 8, 2015
Either usability improvements
@Aaronontheweb Aaronontheweb merged commit af146b0 into akkadotnet:dev Jul 8, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants