aboutsummaryrefslogtreecommitdiff
path: root/lib/zipper.ml
blob: 37e14dee7480680556e9351bc985b67afbafb332 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
type zipper =
  { above : string list
  ; selected : string
  ; below : string list
  }

let up (zipper : zipper) =
  match zipper.above with
  | [] -> zipper
  | a :: rest -> { above = rest; selected = a; below = zipper.selected :: zipper.below }


let down (zipper : zipper) =
  match zipper.below with
  | [] -> zipper
  | a :: rest -> { below = rest; selected = a; above = zipper.selected :: zipper.above }


let selected zipper = zipper.selected

let to_array zipper =
  List.concat [ zipper.above; [ zipper.selected ]; zipper.below ] |> Array.of_list