Skip to content

Instantly share code, notes, and snippets.

@njlr
Created May 16, 2017 14:03
Show Gist options
  • Save njlr/22e6d06d219628a583a12f372a849902 to your computer and use it in GitHub Desktop.
Save njlr/22e6d06d219628a583a12f372a849902 to your computer and use it in GitHub Desktop.
Either<string, int> myEither = left("hello"); // constructs a either containing a leftValue;
int count = myEither
.rightMap([](auto num) { return num + 1; }) // adds 1 if rightValue is present
.leftMap([](auto str) { return str + "world"; }) // appends "world" if leftValue is present
.leftMap([](auto str) { return str.size(); })
.join(); // both sides have now the same type, lets join...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment