whenJusts
whenJusts<
Xs
,M
>(xs
,f
):ArgJust
<Xs
> extendsnever
[] ?Nothing
: [Nothing
] extends [Xs
[number
]] ?Nothing
|M
:M
whenJusts
takes a tuple of Maybe
s and a function that takes the values of the Just
s and
returns a Maybe
of the result of the function.
Example
whenJusts([{ right: 'foo' }, { right: 'bar' }], ([x0, x1]) => `${x0}${x1}`)// => "foobar"
whenJusts([{ left: 'bar' }, { right: 'fooz' }], ([x0, x1]) => `${x0}${x1}`)// => { left: "bar" }
Type Parameters
• Xs extends unknown
[]
The maybe types.
• M extends unknown
The mapped type.
Parameters
xs
readonly [Xs
]
The maybe values.
f
(x
) => M
The map function.
Returns
ArgJust
<Xs
> extends never
[] ? Nothing
: [Nothing
] extends [Xs
[number
]] ? Nothing
| M
: M
The mapped value if just.