aboutsummaryrefslogtreecommitdiff
path: root/src/content/chapter1_functions/lesson03_higher_order_functions/code.gleam
blob: 43b6ca49cfcfe5eb50f5a597ee86951bab5b9d21 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import gleam/io

pub fn main() {
  // Call a function with another function
  io.debug(twice(1, add_one))

  // Functions can be assigned to variables
  let my_function = add_one
  io.debug(my_function(100))
}

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

fn add_one(argument: Int) -> Int {
  argument + 1
}