Pure Roc implementation of Result.alterErr

This commit is contained in:
Marten/Qqwy 2022-07-07 22:44:13 +02:00 committed by Folkert
parent 7a2c2f6d1d
commit 5632d07179
No known key found for this signature in database
GPG key ID: 1F17F6FFD112B97C

View file

@ -92,3 +92,20 @@ after = \result, transform ->
transform v
Err e ->
Err e
## If the result is `Err`, transform the entire result by running a conversion
## function on the value the `Err` holds. Then return that new result.
##
## (If the result is `Ok`, this has no effect. Use `after` to transform an `Ok`.)
##
## >>> Result.afterErr (Ok 10) \errorNum -> Str.toNat errorNum
##
## >>> Result.afterErr (Err "42") \errorNum -> Str.toNat errorNum
after : Result a err, (err -> Result a otherErr) -> Result a otherErr
after = \result, transform ->
when result is
Ok v ->
v
Err e ->
transform e