From ab2b9a982ede817362072623ff9ae2aa42e083da Mon Sep 17 00:00:00 2001 From: Louis Pilfold Date: Thu, 18 Jan 2024 20:34:43 +0000 Subject: Move recursion lessons together --- .../lesson08_multiple_subjects/code.gleam | 17 +++++++++++++++++ .../lesson08_multiple_subjects/text.html | 13 +++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 src/content/chapter2_flow_control/lesson08_multiple_subjects/code.gleam create mode 100644 src/content/chapter2_flow_control/lesson08_multiple_subjects/text.html (limited to 'src/content/chapter2_flow_control/lesson08_multiple_subjects') diff --git a/src/content/chapter2_flow_control/lesson08_multiple_subjects/code.gleam b/src/content/chapter2_flow_control/lesson08_multiple_subjects/code.gleam new file mode 100644 index 0000000..d7aa34a --- /dev/null +++ b/src/content/chapter2_flow_control/lesson08_multiple_subjects/code.gleam @@ -0,0 +1,17 @@ +import gleam/io +import gleam/int + +pub fn main() { + let x = int.random(2) + let y = int.random(2) + io.debug(x) + io.debug(y) + + let result = case x, y { + 0, 0 -> "Both are zero" + 0, _ -> "First is zero" + _, 0 -> "Second is zero" + _, _ -> "Neither are zero" + } + io.debug(result) +} diff --git a/src/content/chapter2_flow_control/lesson08_multiple_subjects/text.html b/src/content/chapter2_flow_control/lesson08_multiple_subjects/text.html new file mode 100644 index 0000000..26a7ea3 --- /dev/null +++ b/src/content/chapter2_flow_control/lesson08_multiple_subjects/text.html @@ -0,0 +1,13 @@ +

+ Sometimes it is useful to pattern match on multiple values at the same time in + one case experession. +

+

+ To do this you can give multiple subjects and multiple patterns, separated + commas. +

+

+ When matching on multiple subjects there must be the same number of patterns + as there are subjects. Try removing one of the _, sub-patterns to + see the compile time error that is returned. +

-- cgit v1.2.3