Skip to content

Instantly share code, notes, and snippets.

@3pmTea
3pmTea / render_table.ml
Last active April 27, 2019 11:51
render_table example introduced in Real World OCaml, enhanced with padding support
let max_widths header rows =
let lengths l = List.map ~f:String.length l in
List.fold rows
~init:(lengths header)
~f:(fun acc row -> List.map2_exn ~f:Int.max acc (lengths row));;
let render_separator padding widths =
let pieces = List.map widths
~f:(fun w -> String.make (w + 2 * padding) '-')
in