mirror of
https://github.com/roc-lang/roc.git
synced 2024-09-21 15:59:20 +03:00
Rename Result.afterErr to Result.onErr
This commit is contained in:
parent
0acab0eef3
commit
145bd8b4a2
@ -1,5 +1,5 @@
|
|||||||
interface Result
|
interface Result
|
||||||
exposes [Result, isOk, isErr, map, mapErr, try, afterErr, withDefault]
|
exposes [Result, isOk, isErr, map, mapErr, try, onErr, withDefault]
|
||||||
imports [Bool.{ Bool }]
|
imports [Bool.{ Bool }]
|
||||||
|
|
||||||
## The result of an operation that could fail: either the operation went
|
## 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
|
## 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.
|
## 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
|
## >>> 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`.)
|
## (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
|
## >>> Result.onErr (Err "42") \errorNum -> Str.toNat errorNum
|
||||||
afterErr : Result a err, (err -> Result a otherErr) -> Result a otherErr
|
onErr : Result a err, (err -> Result a otherErr) -> Result a otherErr
|
||||||
afterErr = \result, transform ->
|
onErr = \result, transform ->
|
||||||
when result is
|
when result is
|
||||||
Ok v -> Ok v
|
Ok v -> Ok v
|
||||||
Err e -> transform e
|
Err e -> transform e
|
||||||
|
@ -308,7 +308,7 @@ fn roc_result_after_err() {
|
|||||||
r#"
|
r#"
|
||||||
result : Result Str I64
|
result : Result Str I64
|
||||||
result =
|
result =
|
||||||
Result.tryErr (Ok "already a string") \num ->
|
Result.onErr (Ok "already a string") \num ->
|
||||||
if num < 0 then Ok "negative!" else Err -num
|
if num < 0 then Ok "negative!" else Err -num
|
||||||
|
|
||||||
result
|
result
|
||||||
@ -321,7 +321,7 @@ fn roc_result_after_err() {
|
|||||||
r#"
|
r#"
|
||||||
result : Result Str I64
|
result : Result Str I64
|
||||||
result =
|
result =
|
||||||
Result.tryErr (Err 100) \num ->
|
Result.onErr (Err 100) \num ->
|
||||||
if num < 0 then Ok "negative!" else Err -num
|
if num < 0 then Ok "negative!" else Err -num
|
||||||
|
|
||||||
result
|
result
|
||||||
|
Loading…
Reference in New Issue
Block a user