aboutsummaryrefslogtreecommitdiff
path: root/src/content/chapter5_advanced_features/lesson04_let_assert/code.gleam
diff options
context:
space:
mode:
authorLouis Pilfold <louis@lpil.uk>2024-02-20 12:20:16 +0000
committerLouis Pilfold <louis@lpil.uk>2024-02-20 12:20:16 +0000
commit938f49fc7835501192ccc7db7c1ab3174f050b34 (patch)
tree3e515fa15b6812df9947df80b8c16afd20faa436 /src/content/chapter5_advanced_features/lesson04_let_assert/code.gleam
parente7d45ec089262e8b6731ddf87e65a06f4de07841 (diff)
downloadtour-938f49fc7835501192ccc7db7c1ab3174f050b34.tar.gz
tour-938f49fc7835501192ccc7db7c1ab3174f050b34.zip
Let assert
Diffstat (limited to 'src/content/chapter5_advanced_features/lesson04_let_assert/code.gleam')
-rw-r--r--src/content/chapter5_advanced_features/lesson04_let_assert/code.gleam16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/content/chapter5_advanced_features/lesson04_let_assert/code.gleam b/src/content/chapter5_advanced_features/lesson04_let_assert/code.gleam
new file mode 100644
index 0000000..2ba907a
--- /dev/null
+++ b/src/content/chapter5_advanced_features/lesson04_let_assert/code.gleam
@@ -0,0 +1,16 @@
+import gleam/io
+
+pub fn main() {
+ let a = unsafely_get_first_element([123])
+ io.debug(a)
+
+ let b = unsafely_get_first_element([])
+ io.debug(b)
+}
+
+pub fn unsafely_get_first_element(items: List(a)) -> a {
+ // This will panic if the list is empty.
+ // A regular `let` would not permit this partial pattern
+ let assert [first, ..] = items
+ first
+}