Skip to content

Commit 778ec77

Browse files
giacomocavalierilpil
authored andcommitted
Replace occurrences of list.head in code in favour of list.first
1 parent 22910e4 commit 778ec77

File tree

3 files changed

+28
-28
lines changed

3 files changed

+28
-28
lines changed

src/gleam/list.gleam

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,8 @@ pub fn is_empty(list: List(a)) -> Bool {
189189
pub fn contains(list: List(a), any elem: a) -> Bool {
190190
case list {
191191
[] -> False
192-
[head, ..] if head == elem -> True
193-
[_, ..tail] -> contains(tail, elem)
192+
[first, ..] if first == elem -> True
193+
[_, ..rest] -> contains(rest, elem)
194194
}
195195
}
196196

@@ -624,7 +624,7 @@ pub fn prepend(to list: List(a), this item: a) -> List(a) {
624624
fn reverse_and_prepend(list prefix: List(a), to suffix: List(a)) -> List(a) {
625625
case prefix {
626626
[] -> suffix
627-
[head, ..tail] -> reverse_and_prepend(list: tail, to: [head, ..suffix])
627+
[first, ..rest] -> reverse_and_prepend(list: rest, to: [first, ..suffix])
628628
}
629629
}
630630

@@ -903,9 +903,9 @@ pub fn find_map(
903903
pub fn all(in list: List(a), satisfying predicate: fn(a) -> Bool) -> Bool {
904904
case list {
905905
[] -> True
906-
[head, ..tail] ->
907-
case predicate(head) {
908-
True -> all(tail, predicate)
906+
[first, ..rest] ->
907+
case predicate(first) {
908+
True -> all(rest, predicate)
909909
False -> False
910910
}
911911
}
@@ -940,10 +940,10 @@ pub fn all(in list: List(a), satisfying predicate: fn(a) -> Bool) -> Bool {
940940
pub fn any(in list: List(a), satisfying predicate: fn(a) -> Bool) -> Bool {
941941
case list {
942942
[] -> False
943-
[head, ..tail] ->
944-
case predicate(head) {
943+
[first, ..rest] ->
944+
case predicate(first) {
945945
True -> True
946-
False -> any(tail, predicate)
946+
False -> any(rest, predicate)
947947
}
948948
}
949949
}
@@ -1732,9 +1732,9 @@ fn do_take_while(
17321732
) -> List(a) {
17331733
case list {
17341734
[] -> reverse(acc)
1735-
[head, ..tail] ->
1736-
case predicate(head) {
1737-
True -> do_take_while(tail, predicate, [head, ..acc])
1735+
[first, ..rest] ->
1736+
case predicate(first) {
1737+
True -> do_take_while(rest, predicate, [first, ..acc])
17381738
False -> reverse(acc)
17391739
}
17401740
}
@@ -1764,14 +1764,14 @@ fn do_chunk(
17641764
acc: List(List(a)),
17651765
) -> List(List(a)) {
17661766
case list {
1767-
[head, ..tail] -> {
1768-
let key = f(head)
1767+
[first, ..rest] -> {
1768+
let key = f(first)
17691769
case key == previous_key {
17701770
False -> {
17711771
let new_acc = [reverse(current_chunk), ..acc]
1772-
do_chunk(tail, f, key, [head], new_acc)
1772+
do_chunk(rest, f, key, [first], new_acc)
17731773
}
1774-
_true -> do_chunk(tail, f, key, [head, ..current_chunk], acc)
1774+
_true -> do_chunk(rest, f, key, [first, ..current_chunk], acc)
17751775
}
17761776
}
17771777
_empty -> reverse([reverse(current_chunk), ..acc])
@@ -1791,7 +1791,7 @@ fn do_chunk(
17911791
pub fn chunk(in list: List(a), by f: fn(a) -> key) -> List(List(a)) {
17921792
case list {
17931793
[] -> []
1794-
[head, ..tail] -> do_chunk(tail, f, f(head), [head], [])
1794+
[first, ..rest] -> do_chunk(rest, f, f(first), [first], [])
17951795
}
17961796
}
17971797

@@ -1808,11 +1808,11 @@ fn do_sized_chunk(
18081808
[] -> reverse(acc)
18091809
remaining -> reverse([reverse(remaining), ..acc])
18101810
}
1811-
[head, ..tail] -> {
1812-
let chunk = [head, ..current_chunk]
1811+
[first, ..rest] -> {
1812+
let chunk = [first, ..current_chunk]
18131813
case left > 1 {
1814-
False -> do_sized_chunk(tail, count, count, [], [reverse(chunk), ..acc])
1815-
True -> do_sized_chunk(tail, count, left - 1, chunk, acc)
1814+
False -> do_sized_chunk(rest, count, count, [], [reverse(chunk), ..acc])
1815+
True -> do_sized_chunk(rest, count, left - 1, chunk, acc)
18161816
}
18171817
}
18181818
}
@@ -1864,7 +1864,7 @@ pub fn sized_chunk(in list: List(a), into count: Int) -> List(List(a)) {
18641864
pub fn reduce(over list: List(a), with fun: fn(a, a) -> a) -> Result(a, Nil) {
18651865
case list {
18661866
[] -> Error(Nil)
1867-
[head, ..tail] -> Ok(fold(tail, head, fun))
1867+
[first, ..rest] -> Ok(fold(rest, first, fun))
18681868
}
18691869
}
18701870

src/gleam/map.gleam

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ pub fn update(
557557
fn do_fold(list: List(#(k, v)), initial: acc, fun: fn(acc, k, v) -> acc) -> acc {
558558
case list {
559559
[] -> initial
560-
[#(k, v), ..tail] -> do_fold(tail, fun(initial, k, v), fun)
560+
[#(k, v), ..rest] -> do_fold(rest, fun(initial, k, v), fun)
561561
}
562562
}
563563

src/gleam/string.gleam

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -812,8 +812,8 @@ if erlang {
812812
acc: List(UtfCodepoint),
813813
) -> List(UtfCodepoint) {
814814
case bit_string {
815-
<<head:utf8_codepoint, rest:binary>> ->
816-
do_to_utf_codepoints_impl(rest, [head, ..acc])
815+
<<first:utf8_codepoint, rest:binary>> ->
816+
do_to_utf_codepoints_impl(rest, [first, ..acc])
817817
<<>> -> acc
818818
}
819819
}
@@ -868,10 +868,10 @@ if erlang {
868868
acc: BitString,
869869
) -> BitString {
870870
case utf_codepoints {
871-
[head, ..tail] ->
871+
[first, ..rest] ->
872872
do_from_utf_codepoints_impl(
873-
tail,
874-
<<acc:bit_string, head:utf8_codepoint>>,
873+
rest,
874+
<<acc:bit_string, first:utf8_codepoint>>,
875875
)
876876
[] -> acc
877877
}

0 commit comments

Comments
 (0)