diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/gleam/dynamic.gleam | 2 | ||||
-rw-r--r-- | src/gleam/list.gleam | 18 |
2 files changed, 10 insertions, 10 deletions
diff --git a/src/gleam/dynamic.gleam b/src/gleam/dynamic.gleam index c82ae86..4fbee8b 100644 --- a/src/gleam/dynamic.gleam +++ b/src/gleam/dynamic.gleam @@ -172,7 +172,7 @@ pub fn typed_list( ) -> Result(List(inner), String) { dynamic |> list - |> result.then(list_mod.traverse(_, decoder_type)) + |> result.then(list_mod.try_map(_, decoder_type)) } /// Check to see if a Dynamic value is a map with a specific field, and return diff --git a/src/gleam/list.gleam b/src/gleam/list.gleam index a919d9c..de04d2c 100644 --- a/src/gleam/list.gleam +++ b/src/gleam/list.gleam @@ -273,7 +273,7 @@ pub fn index_map(list: List(a), with fun: fn(Int, a) -> b) -> List(b) { do_index_map(list, fun, 0, []) } -fn do_traverse( +fn do_try_map( list: List(a), fun: fn(a) -> Result(b, e), acc: List(b), @@ -281,7 +281,7 @@ fn do_traverse( case list { [] -> Ok(reverse(acc)) [x, ..xs] -> case fun(x) { - Ok(y) -> do_traverse(xs, fun, [y, ..acc]) + Ok(y) -> do_try_map(xs, fun, [y, ..acc]) Error(error) -> Error(error) } } @@ -299,23 +299,23 @@ fn do_traverse( /// /// ## Examples /// -/// > traverse([1, 2, 3], fn(x) { Ok(x + 2) }) +/// > try_map([1, 2, 3], fn(x) { Ok(x + 2) }) /// Ok([3, 4, 5]) /// -/// > traverse([1, 2, 3], fn(x) { Error(0) }) +/// > try_map([1, 2, 3], fn(x) { Error(0) }) /// Error(0) /// -/// > traverse([[1], [2, 3]], head) +/// > try_map([[1], [2, 3]], head) /// Ok([1, 2]) /// -/// > traverse([[1], [], [2]], head) +/// > try_map([[1], [], [2]], head) /// Error(Nil) /// -pub fn traverse( - list: List(a), +pub fn try_map( + over list: List(a), with fun: fn(a) -> Result(b, e), ) -> Result(List(b), e) { - do_traverse(list, fun, []) + do_try_map(list, fun, []) } /// Returns a list that is the given list with up to the given number of |