aboutsummaryrefslogtreecommitdiff
path: root/src/content/chapter2_flow_control/lesson11_guards/code.gleam
blob: 3744228a0c6af357f6f26debb4e5a819eec4a907 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import gleam/io

pub fn main() {
  let numbers = [1, 2, 3, 4, 5]
  io.debug(get_first_larger(numbers, 3))
  io.debug(get_first_larger(numbers, 5))
}

fn get_first_larger(lists: List(Int), limit: Int) -> Int {
  case lists {
    [first, ..] if first > limit -> first
    [_, ..rest] -> get_first_larger(rest, limit)
    [] -> 0
  }
}