Either values

The Either values, like the Optionals, are a way to represents uncertain data, but at this time, instead of None state, it has another state called Left that can store useful data.

The either values limits the access of data contained in it, allowing the developer to access just the correct data through pattern matching.

Is possible to create an Either value that can be store an int and a boolean, but only one at time. These values can be in one of the two possibles states:

  • Left - When contains a value typed by Left;

  • Right - When contains a value typed by Right.

By convention, the Right type is used to represents correct values, and the Left type is used to represents data of incorrect values, similar to Optional but in this case, both states has a valid value.

This implementation was strongly inspired by Haskell Either type.

The implementations behind this concepts were done in two steps: the Either type and the module.

Last updated