Helpers for error handling with multiple Result values
Given a 2-tuple of Result values, if both values are Ok, return an Ok
result containing the 2-tuple of values; otherwise, return an Err value.
(Ok 1, Ok 2)
|> Toolkit.Result.zip "ERROR"
--> Ok (1,2)
(Ok 1, Err "..")
|> Toolkit.Result.zip "ERROR"
--> Err "ERROR"Given a 3-tuple of Result values, if all three values are Ok, return an
Ok result containing the 3-tuple of values; otherwise, return an Err
value.
Given a 4-tuple of Result values, if all three values are Ok, return an
Ok result containing the 4-tuple of values; otherwise, return an Err
value.
Given a list of Result values, if all values are Ok, return an Ok
result containing the list of values; otherwise, return an error message. When
passed an empty list, returns Ok [].
[Ok 1, Ok 2]
|> Toolkit.Result.zipList "ERROR"
--> Ok [1,2]
[Ok 1, Err ".."]
|> Toolkit.Result.zipList "ERROR"
--> Err "ERROR"
[]
|> Toolkit.Result.zipList "ERROR"
--> Ok []Given a list of Result values, return a list containing only the success
values.
[ Ok 1
, Ok 2
, Err ".."
]
|> Toolkit.Result.filter
--> [1, 2]
Apply a function that returns a
Resultvalue, with the initial value as the default (equivalent tof x |> Result.withDefault x). Note that the type returned in anOkresult must match the type of the initial value.