-
v1, Beta 2 Pre-Release
released this
2024-07-29 20:50:13 +00:00 | 4 commits to main since this releaseBREAKING CHANGE
Option->is()
has been renamedOption->contains()
for consistency withResult
(and any future collection implementation).FEATURES
BothOption
andResult
now support:bind
: takes a callback that accepts the Some or OK value and returns anOption
orResult
, respectively. If theOption
is None or theResult
is Error, the callback will be skipped. This allows what is termed "railway-oriented programming" where every call is an opportunity to short-circuit the rest of the calls and return the Error result (or None).contains
: takes a value and an optionalstrict:
parameter; it returnstrue
if the Some or OK value matches the value provided, orfalse
otherwise.exists
: takes a callback that accepts the Some or OK value and returnsbool
; None or Error results always returnfalse
.toArray
: converts a SomeOption
and an OKResult
to a one-item array, and converts a NoneOption
and an ErrorResult
to an empty array.
Additionally,
Option
now has agetOrThrow
method that takes a callback that returns anException
. If theOption
is Some, the value is returned; if it is None, the callback is called and the resultingException
is thrown.Downloads