aboutsummaryrefslogtreecommitdiff
path: root/src/content/chapter1_functions/lesson04_anonymous_functions/code.gleam
blob: 2b037e0659e8ae1acfc3aba14bf22156e9969725 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
import gleam/io

pub fn main() {
  // Assign an anonymous function to a variable
  let add_one = fn(a) { a + 1 }
  io.debug(twice(1, add_one))

  // Pass an anonymous function as an argument
  io.debug(twice(1, fn(a) { a * 2 }))
}

fn twice(argument: Int, function: fn(Int) -> Int) -> Int {
  function(function(argument))
}