diff options
author | Giacomo Cavalieri <giacomo.cavalieri@icloud.com> | 2023-05-25 17:17:30 +0200 |
---|---|---|
committer | Louis Pilfold <louis@lpil.uk> | 2023-05-25 16:35:25 +0100 |
commit | 778ec774144e72e9ee1810a60bfbc39a824d1eb8 (patch) | |
tree | 08bdd0135bb55d69e33efaf166ce4dad47d919b4 /src | |
parent | 22910e44979f3530a2ef6fd791f2214697e0a659 (diff) | |
download | gleam_stdlib-778ec774144e72e9ee1810a60bfbc39a824d1eb8.tar.gz gleam_stdlib-778ec774144e72e9ee1810a60bfbc39a824d1eb8.zip |
Replace occurrences of `list.head` in code in favour of `list.first`
Diffstat (limited to 'src')
-rw-r--r-- | src/gleam/list.gleam | 44 | ||||
-rw-r--r-- | src/gleam/map.gleam | 2 | ||||
-rw-r--r-- | src/gleam/string.gleam | 10 |
3 files changed, 28 insertions, 28 deletions
diff --git a/src/gleam/list.gleam b/src/gleam/list.gleam index 8d8ddfe..cb25d06 100644 --- a/src/gleam/list.gleam +++ b/src/gleam/list.gleam @@ -189,8 +189,8 @@ pub fn is_empty(list: List(a)) -> Bool { pub fn contains(list: List(a), any elem: a) -> Bool { case list { [] -> False - [head, ..] if head == elem -> True - [_, ..tail] -> contains(tail, elem) + [first, ..] if first == elem -> True + [_, ..rest] -> contains(rest, elem) } } @@ -624,7 +624,7 @@ pub fn prepend(to list: List(a), this item: a) -> List(a) { fn reverse_and_prepend(list prefix: List(a), to suffix: List(a)) -> List(a) { case prefix { [] -> suffix - [head, ..tail] -> reverse_and_prepend(list: tail, to: [head, ..suffix]) + [first, ..rest] -> reverse_and_prepend(list: rest, to: [first, ..suffix]) } } @@ -903,9 +903,9 @@ pub fn find_map( pub fn all(in list: List(a), satisfying predicate: fn(a) -> Bool) -> Bool { case list { [] -> True - [head, ..tail] -> - case predicate(head) { - True -> all(tail, predicate) + [first, ..rest] -> + case predicate(first) { + True -> all(rest, predicate) False -> False } } @@ -940,10 +940,10 @@ pub fn all(in list: List(a), satisfying predicate: fn(a) -> Bool) -> Bool { pub fn any(in list: List(a), satisfying predicate: fn(a) -> Bool) -> Bool { case list { [] -> False - [head, ..tail] -> - case predicate(head) { + [first, ..rest] -> + case predicate(first) { True -> True - False -> any(tail, predicate) + False -> any(rest, predicate) } } } @@ -1732,9 +1732,9 @@ fn do_take_while( ) -> List(a) { case list { [] -> reverse(acc) - [head, ..tail] -> - case predicate(head) { - True -> do_take_while(tail, predicate, [head, ..acc]) + [first, ..rest] -> + case predicate(first) { + True -> do_take_while(rest, predicate, [first, ..acc]) False -> reverse(acc) } } @@ -1764,14 +1764,14 @@ fn do_chunk( acc: List(List(a)), ) -> List(List(a)) { case list { - [head, ..tail] -> { - let key = f(head) + [first, ..rest] -> { + let key = f(first) case key == previous_key { False -> { let new_acc = [reverse(current_chunk), ..acc] - do_chunk(tail, f, key, [head], new_acc) + do_chunk(rest, f, key, [first], new_acc) } - _true -> do_chunk(tail, f, key, [head, ..current_chunk], acc) + _true -> do_chunk(rest, f, key, [first, ..current_chunk], acc) } } _empty -> reverse([reverse(current_chunk), ..acc]) @@ -1791,7 +1791,7 @@ fn do_chunk( pub fn chunk(in list: List(a), by f: fn(a) -> key) -> List(List(a)) { case list { [] -> [] - [head, ..tail] -> do_chunk(tail, f, f(head), [head], []) + [first, ..rest] -> do_chunk(rest, f, f(first), [first], []) } } @@ -1808,11 +1808,11 @@ fn do_sized_chunk( [] -> reverse(acc) remaining -> reverse([reverse(remaining), ..acc]) } - [head, ..tail] -> { - let chunk = [head, ..current_chunk] + [first, ..rest] -> { + let chunk = [first, ..current_chunk] case left > 1 { - False -> do_sized_chunk(tail, count, count, [], [reverse(chunk), ..acc]) - True -> do_sized_chunk(tail, count, left - 1, chunk, acc) + False -> do_sized_chunk(rest, count, count, [], [reverse(chunk), ..acc]) + True -> do_sized_chunk(rest, count, left - 1, chunk, acc) } } } @@ -1864,7 +1864,7 @@ pub fn sized_chunk(in list: List(a), into count: Int) -> List(List(a)) { pub fn reduce(over list: List(a), with fun: fn(a, a) -> a) -> Result(a, Nil) { case list { [] -> Error(Nil) - [head, ..tail] -> Ok(fold(tail, head, fun)) + [first, ..rest] -> Ok(fold(rest, first, fun)) } } diff --git a/src/gleam/map.gleam b/src/gleam/map.gleam index fd9f961..6f963bc 100644 --- a/src/gleam/map.gleam +++ b/src/gleam/map.gleam @@ -557,7 +557,7 @@ pub fn update( fn do_fold(list: List(#(k, v)), initial: acc, fun: fn(acc, k, v) -> acc) -> acc { case list { [] -> initial - [#(k, v), ..tail] -> do_fold(tail, fun(initial, k, v), fun) + [#(k, v), ..rest] -> do_fold(rest, fun(initial, k, v), fun) } } diff --git a/src/gleam/string.gleam b/src/gleam/string.gleam index cf7d48d..89efb5d 100644 --- a/src/gleam/string.gleam +++ b/src/gleam/string.gleam @@ -812,8 +812,8 @@ if erlang { acc: List(UtfCodepoint), ) -> List(UtfCodepoint) { case bit_string { - <<head:utf8_codepoint, rest:binary>> -> - do_to_utf_codepoints_impl(rest, [head, ..acc]) + <<first:utf8_codepoint, rest:binary>> -> + do_to_utf_codepoints_impl(rest, [first, ..acc]) <<>> -> acc } } @@ -868,10 +868,10 @@ if erlang { acc: BitString, ) -> BitString { case utf_codepoints { - [head, ..tail] -> + [first, ..rest] -> do_from_utf_codepoints_impl( - tail, - <<acc:bit_string, head:utf8_codepoint>>, + rest, + <<acc:bit_string, first:utf8_codepoint>>, ) [] -> acc } |