From 71351fcd918ef9e740f257e5040b4b1b6bae6645 Mon Sep 17 00:00:00 2001 From: ellipticview Date: Sat, 4 May 2024 11:32:00 +0200 Subject: Added example to anonymous functions --- .../chapter1_functions/lesson04_anonymous_functions/code.gleam | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/content/chapter1_functions/lesson04_anonymous_functions/code.gleam') diff --git a/src/content/chapter1_functions/lesson04_anonymous_functions/code.gleam b/src/content/chapter1_functions/lesson04_anonymous_functions/code.gleam index e58659a..df7a6f9 100644 --- a/src/content/chapter1_functions/lesson04_anonymous_functions/code.gleam +++ b/src/content/chapter1_functions/lesson04_anonymous_functions/code.gleam @@ -7,6 +7,11 @@ pub fn main() { // Pass an anonymous function as an argument io.debug(twice(1, fn(a) { a * 2 })) + + let secret_number = 42 + // This anonymous function always returns 42 + let secret = fn() { secret_number } + io.debug(secret()) } fn twice(argument: Int, my_function: fn(Int) -> Int) -> Int { -- cgit v1.2.3