mirror of
https://github.com/roc-lang/roc.git
synced 2024-09-21 07:49:17 +03:00
Rename Result.afterErr to Result.onErr
This commit is contained in:
parent
0acab0eef3
commit
145bd8b4a2
@ -1,5 +1,5 @@
|
||||
interface Result
|
||||
exposes [Result, isOk, isErr, map, mapErr, try, afterErr, withDefault]
|
||||
exposes [Result, isOk, isErr, map, mapErr, try, onErr, withDefault]
|
||||
imports [Bool.{ Bool }]
|
||||
|
||||
## The result of an operation that could fail: either the operation went
|
||||
@ -70,7 +70,7 @@ mapErr = \result, transform ->
|
||||
## If the result is `Ok`, transform the entire result by running a conversion
|
||||
## function on the value the `Ok` holds. Then return that new result.
|
||||
##
|
||||
## (If the result is `Err`, this has no effect. Use `afterErr` to transform an `Err`.)
|
||||
## (If the result is `Err`, this has no effect. Use `onErr` to transform an `Err`.)
|
||||
##
|
||||
## >>> Result.try (Ok -1) \num -> if num < 0 then Err "negative!" else Ok -num
|
||||
##
|
||||
@ -86,11 +86,11 @@ try = \result, transform ->
|
||||
##
|
||||
## (If the result is `Ok`, this has no effect. Use `try` to transform an `Ok`.)
|
||||
##
|
||||
## >>> Result.afterErr (Ok 10) \errorNum -> Str.toNat errorNum
|
||||
## >>> Result.onErr (Ok 10) \errorNum -> Str.toNat errorNum
|
||||
##
|
||||
## >>> Result.afterErr (Err "42") \errorNum -> Str.toNat errorNum
|
||||
afterErr : Result a err, (err -> Result a otherErr) -> Result a otherErr
|
||||
afterErr = \result, transform ->
|
||||
## >>> Result.onErr (Err "42") \errorNum -> Str.toNat errorNum
|
||||
onErr : Result a err, (err -> Result a otherErr) -> Result a otherErr
|
||||
onErr = \result, transform ->
|
||||
when result is
|
||||
Ok v -> Ok v
|
||||
Err e -> transform e
|
||||
|
@ -308,7 +308,7 @@ fn roc_result_after_err() {
|
||||
r#"
|
||||
result : Result Str I64
|
||||
result =
|
||||
Result.tryErr (Ok "already a string") \num ->
|
||||
Result.onErr (Ok "already a string") \num ->
|
||||
if num < 0 then Ok "negative!" else Err -num
|
||||
|
||||
result
|
||||
@ -321,7 +321,7 @@ fn roc_result_after_err() {
|
||||
r#"
|
||||
result : Result Str I64
|
||||
result =
|
||||
Result.tryErr (Err 100) \num ->
|
||||
Result.onErr (Err 100) \num ->
|
||||
if num < 0 then Ok "negative!" else Err -num
|
||||
|
||||
result
|
||||
|
Loading…
Reference in New Issue
Block a user