Skip to content

Instantly share code, notes, and snippets.

@astarasikov
Created November 27, 2014 19:37
Show Gist options
  • Save astarasikov/faf14862ae23259210c8 to your computer and use it in GitHub Desktop.
Save astarasikov/faf14862ae23259210c8 to your computer and use it in GitHub Desktop.
let rec revZipWithDefault accum dval lsta lstb =
match lsta with
| ha :: ta ->
(match lstb with
| hb :: tb -> zipWithDefault ((ha, hb) :: accum) dval ta tb
| _ -> zipWithDefault ((ha, dval) :: accum) dval ta [])
| _ ->
(match lstb with
| hd :: tl -> zipWithDefault ((dval, hd) :: accum) dval [] tl
| _ -> accum);;
let zipInts a b = revZipWithDefault [] 0 a b |> List.rev;;
zipInts [1;2;3] [4;5] |> map (fun (a, b) -> a + b);;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment