diff --git a/src/content/chapter2_flow_control/lesson04_list_patterns/code.gleam b/src/content/chapter2_flow_control/lesson04_list_patterns/code.gleam
index 1b71feb..a2c1fe3 100644
--- a/src/content/chapter2_flow_control/lesson04_list_patterns/code.gleam
+++ b/src/content/chapter2_flow_control/lesson04_list_patterns/code.gleam
@@ -10,6 +10,7 @@ pub fn main() {
[] -> "Empty list"
[1] -> "List of just 1"
[4, ..] -> "List starting with 4"
+ [3, ..rest] -> "Starts with a 3, captures the rest"
[_, _] -> "List of 2 elements"
_ -> "Some other list"
}
diff --git a/src/content/chapter2_flow_control/lesson04_list_patterns/en.html b/src/content/chapter2_flow_control/lesson04_list_patterns/en.html
index de55eef..4d68138 100644
--- a/src/content/chapter2_flow_control/lesson04_list_patterns/en.html
+++ b/src/content/chapter2_flow_control/lesson04_list_patterns/en.html
@@ -11,5 +11,8 @@
The spread pattern ..
can be used to match the rest of the list.
The pattern [1, ..]
matches any list that starts with
1
. The pattern [_, _, ..]
matches any list that has
- at least two elements.
+ at least two elements. By adding a variable name after the ..
, you
+ can capture the remaining elements of the list. The pattern [_, ..rest]
+ will match a list with at least one element and assign the rest of the elements
+ to the variable rest
.
gleam/list
-
+
module to iterate across a list, at times you may prefer to work
with the list directly.
- The [first, ..rest]
pattern matches on a list with at least one
- element, assigning the first element to the variable first
and
- the rest of the list to the variable rest
. By using this pattern
- and a pattern for the empty list []
a function can run code on
- each element of a list until the end is reached.
+ By using the [first, ..rest]
pattern and a pattern for the empty
+ list []
a function can run code on each element of a list until
+ the end is reached.
This code sums a list by recursing over the list and adding each int to a