Skip to content

Instantly share code, notes, and snippets.

@lambdahands lambdahands/

Last active Aug 29, 2015
What would you like to do?
module ListExtra = struct
open Core.Std
(*- Maps a function to each "column" in a list of "rows".
mapv [[1;2;3]; [3;4;5]] ~f:(List.fold ~init:0 ~f:(+));;
- : int list = [4; 6; 8]
let mapv ls ~f = let open List in
let cmp x y = if length x = length y then 0
else if length x > length y then 1
else -1 in
let min = min_elt ls ~cmp:cmp in
let fn' i _ = map ls ~f:(fun x -> nth_exn x i) |> f
in match min with
| Some m' -> mapi m' ~f:fn'
| None -> []
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.