mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-13 15:26:24 +00:00
Merge pull request #4227 from snprajwal/list-expose-walktry
builtin(list): expose walkTry
This commit is contained in:
commit
addfa29a56
2 changed files with 3 additions and 2 deletions
|
@ -39,6 +39,7 @@ interface List
|
||||||
max,
|
max,
|
||||||
map4,
|
map4,
|
||||||
mapTry,
|
mapTry,
|
||||||
|
walkTry,
|
||||||
dropFirst,
|
dropFirst,
|
||||||
joinMap,
|
joinMap,
|
||||||
any,
|
any,
|
||||||
|
@ -959,9 +960,8 @@ mapTry = \list, toResult ->
|
||||||
Result.map (toResult elem) \ok ->
|
Result.map (toResult elem) \ok ->
|
||||||
List.append state ok
|
List.append state ok
|
||||||
|
|
||||||
## This is the same as `iterate` but with Result instead of [Continue, Break].
|
## This is the same as `iterate` but with [Result] instead of `[Continue, Break]`.
|
||||||
## Using `Result` saves a conditional in `mapTry`.
|
## Using `Result` saves a conditional in `mapTry`.
|
||||||
## It might be useful to expose this in userspace?
|
|
||||||
walkTry : List elem, state, (state, elem -> Result state err) -> Result state err
|
walkTry : List elem, state, (state, elem -> Result state err) -> Result state err
|
||||||
walkTry = \list, init, func ->
|
walkTry = \list, init, func ->
|
||||||
walkTryHelp list init func 0 (List.len list)
|
walkTryHelp list init func 0 (List.len list)
|
||||||
|
|
|
@ -1373,6 +1373,7 @@ define_builtins! {
|
||||||
72 LIST_SUBLIST_LOWLEVEL: "sublistLowlevel"
|
72 LIST_SUBLIST_LOWLEVEL: "sublistLowlevel"
|
||||||
73 LIST_CAPACITY: "capacity"
|
73 LIST_CAPACITY: "capacity"
|
||||||
74 LIST_MAP_TRY: "mapTry"
|
74 LIST_MAP_TRY: "mapTry"
|
||||||
|
75 LIST_WALK_TRY: "walkTry"
|
||||||
}
|
}
|
||||||
7 RESULT: "Result" => {
|
7 RESULT: "Result" => {
|
||||||
0 RESULT_RESULT: "Result" exposed_type=true // the Result.Result type alias
|
0 RESULT_RESULT: "Result" exposed_type=true // the Result.Result type alias
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue