SRFI 189: Maybe and Either: optional container types

by John Cowan (text) and Wolfgang Corcoran-Mathe (sample implementation)

status: final (2020-07-14)

keywords: Data Structure, Multiple-Value Returns

See also SRFI 195: Multiple-value boxes.


This SRFI defines two disjoint immutable container types known as Maybe and Either, both of which can contain objects collectively known as their payload. A Maybe object is either a Just object or the unique object Nothing (which has no payload); an Either object is either a Right object or a Left object. Maybe represents the concept of optional values; Either represents the concept of values which are either correct (Right) or errors (Left).

Note that the terms Maybe, Just, Nothing, Either, Right, and Left are capitalized in this SRFI so as not to be confused with their ordinary use as English words. Thus "returns Nothing" means "returns the unique Nothing object"; "returns nothing" could be interpreted as "returns no values" or "returns an unspecified value".