Open otto-dev opened 2 years ago
It is often the case that the value A in Option.when cannot be constructed if the predicate is false. Example:
A
Option.when
final headOption = Option.when(list.isNotEmpty, list.first); // this throws
That often defeats the purpose and there is option(predicate, value) for a strict version. I suggest that the when function signature should be
option(predicate, value)
when
static Option<A> when<A>(bool test, Function0<A> value)
for cases where the value cannot be constructed if the predicate is false, or that there should be another method with such a signature. This is analogous to the existing Either.cond(pred, () => r, () => l).
false
Either.cond(pred, () => r, () => l)
It is often the case that the value
A
inOption.when
cannot be constructed if the predicate is false. Example:That often defeats the purpose and there is
option(predicate, value)
for a strict version. I suggest that thewhen
function signature should befor cases where the value cannot be constructed if the predicate is
false
, or that there should be another method with such a signature. This is analogous to the existingEither.cond(pred, () => r, () => l)
.