Given an array or tuple of Maybes, return a Maybe of the array
or tuple values.
Given an array of type Array<Maybe<A> | Maybe<B>>, the resulting type is
Maybe<Array<A | B>>.
Given a tuple of type [Maybe<A>, Maybe<B>], the resulting type is
Maybe<[A, B]>.
If any of the items in the array or tuple are Nothing, the whole
result is Nothing. If all items in the array or tuple are Just,
the whole result is Just.
Examples
Given an array with a mix of Maybe types in it, both allJust and mixed
here will have the type Maybe<Array<string | number>>, but will be Just
and Nothing respectively.
When working with a tuple type, the structure of the tuple is preserved. Here,
for example, result has the type Maybe<[string, number]> and will be
Nothing:
If all of the items in the tuple are Just, the result is Just wrapping the
tuple of the values of the items. Here, for example, result again has the
type Maybe<[string, number]> and will be Just(['hey', 12]:
Note: this does not work with ReadonlyArray. If you have a
ReadonlyArray you wish to operate on, you must cast it to Array insetad.
This cast is always safe here, because Array is a wider type than
ReadonlyArray.
Given an array or tuple of
Maybe
s, return aMaybe
of the array or tuple values.Array<Maybe<A> | Maybe<B>>
, the resulting type isMaybe<Array<A | B>>
.[Maybe<A>, Maybe<B>]
, the resulting type isMaybe<[A, B]>
.If any of the items in the array or tuple are
Nothing
, the whole result isNothing
. If all items in the array or tuple areJust
, the whole result isJust
.Examples
Given an array with a mix of
Maybe
types in it, bothallJust
andmixed
here will have the typeMaybe<Array<string | number>>
, but will beJust
andNothing
respectively.When working with a tuple type, the structure of the tuple is preserved. Here, for example,
result
has the typeMaybe<[string, number]>
and will beNothing
:If all of the items in the tuple are
Just
, the result isJust
wrapping the tuple of the values of the items. Here, for example,result
again has the typeMaybe<[string, number]>
and will beJust(['hey', 12]
:Note: this does not work with
ReadonlyArray
. If you have aReadonlyArray
you wish to operate on, you must cast it toArray
insetad. This cast is always safe here, becauseArray
is a wider type thanReadonlyArray
.