aboutsummaryrefslogtreecommitdiff
path: root/src/content/chapter5_advanced_features/lesson05_let_assert/code.gleam
diff options
context:
space:
mode:
Diffstat (limited to 'src/content/chapter5_advanced_features/lesson05_let_assert/code.gleam')
-rw-r--r--src/content/chapter5_advanced_features/lesson05_let_assert/code.gleam16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/content/chapter5_advanced_features/lesson05_let_assert/code.gleam b/src/content/chapter5_advanced_features/lesson05_let_assert/code.gleam
new file mode 100644
index 0000000..2ba907a
--- /dev/null
+++ b/src/content/chapter5_advanced_features/lesson05_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
+}