Skip to content

Creating a custom Either type with a custom fixed Left type. #1273

Closed Answered by louthy
kasozivincent asked this question in Q&A
Discussion options

You must be logged in to vote

If you're not willing to update language version (which is a very weird position to take) then the only way is to wrap the existing Either implementation in a new type:

public struct Thing<A>
{
    readonly Either<YourErrorType, A> either;

    public Thing<B> Map<B>(Func<A, B> f) =>
        new Thing<B>(either.Map(f));

    public Thing<B> Bind<B>(Func<A, Thing<B>> f) =>
        new Thing<B>(either.Bind(x => f(x).either));

    ...
}

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by kasozivincent
Comment options

You must be logged in to vote
0 replies
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
Converted from issue

This discussion was converted from issue #1272 on November 14, 2023 18:28.