diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/gleam/list.gleam | 17 |
1 files changed, 5 insertions, 12 deletions
diff --git a/src/gleam/list.gleam b/src/gleam/list.gleam index 6278c6e..07a6953 100644 --- a/src/gleam/list.gleam +++ b/src/gleam/list.gleam @@ -882,6 +882,8 @@ pub fn intersperse(list: List(a), with elem: a) -> List(a) { /// /// Error(Nil) is returned if the list is not long enough for the given index. /// +/// For any `index` less than 0 this function behaves as if it was set to 0. +/// /// ## Examples /// /// > at([1, 2, 3], 1) @@ -891,18 +893,9 @@ pub fn intersperse(list: List(a), with elem: a) -> List(a) { /// Error(Nil) /// pub fn at(in list: List(a), get index: Int) -> Result(a, Nil) { - case index < 0 { - True -> Error(Nil) - False -> - case list { - [] -> Error(Nil) - [x, ..rest] -> - case index == 0 { - True -> Ok(x) - False -> at(rest, index - 1) - } - } - } + list + |> drop(index) + |> first } /// Removes any duplicate elements from a given list. |