lam bui
05/22/2022, 4:37 AMDavid Rawson
05/22/2022, 5:37 AMPair
is a tuple with no info about what first
and second
mean. See “tuples obfuscate” in the Google Guava ideas graveyard:
https://github.com/google/guava/wiki/IdeaGraveyard
Either
is an abstraction built for modelling the common scenario where an operation can succeed or fail, with failure represented by left
and success represented by right
. This can be an alternative to declaring functions that have a return type for success but rely on throwing exceptions to indicate failure.
Either
provides functions like fold
, flatMap
etc. that allow chaining operations, and even a comprehension that allows writing imperative code in a block without using flatMap
etc.
TL;DR Pair
is very broad and Either
is suited to a specific use caseephemient
05/22/2022, 9:29 AMlam bui
05/22/2022, 10:22 AMephemient
05/22/2022, 1:20 PMEither<A, A>
contains more information than A | A
. and Arrow's functions are very targeted towards using Either
as an error-handling monad. but yes, exactly