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

pub fn main() {
  io.debug(get_first_non_empty([[], [1, 2, 3], [4, 5]]))
  io.debug(get_first_non_empty([[1, 2], [3, 4, 5], []]))
  io.debug(get_first_non_empty([[], [], []]))
}

fn get_first_non_empty(lists: List(List(t))) -> List(t) {
  case lists {
    [[_, ..] as first, ..] -> first
    [_, ..rest] -> get_first_non_empty(rest)
    [] -> []
  }
}