Module Balance_list_tree

type 'a t = private
  1. | Leaf of 'a
  2. | Node of 'a t Core.Nonempty_list.t
val sexp_of_t : ('a -> Sexplib0.Sexp.t) -> 'a t -> Sexplib0.Sexp.t
val balance : n:int -> 'a list -> 'a t Core.Or_error.t

Balances the given list. Each sublist's length within the tree has the property of being <= n.

The function returns an error if:

  • the length of the list is < 1, or
  • n <= 0, or
  • n = 1, and the length of the list is not exactly 1