summaryrefslogtreecommitdiff
path: root/2024/ocaml/lib/grid/grid.ml
blob: 0d6bc4c0e3969fd6cc372a853f1990183faff449 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
let rec to_grid_aux tokens max_width acc =
  match tokens with
  | [] -> acc
  | h :: t ->
      let new_cell = Cell.create h |> Cell.with_left acc in
      let new_acc = acc |> Cell.with_right new_cell in
      to_grid_aux t max_width new_acc

let to_grid tokens max_width : Cell.t option =
  match tokens with
  | [] -> None
  | h :: t ->
      let first_cell = Cell.create h in
      Some (to_grid_aux t max_width first_cell)