Skip to content

Instantly share code, notes, and snippets.

@Minoru
Last active April 14, 2016 17:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Minoru/c4e6fd1c010027060cf046a0db7ead48 to your computer and use it in GitHub Desktop.
Save Minoru/c4e6fd1c010027060cf046a0db7ead48 to your computer and use it in GitHub Desktop.
OCamlin' along with @rexim
let on f g = fun x y -> f (g x) (g y)
(* uncurry from https://thelema.github.io/batteries-included/hdoc/BatPervasives.html
dunno if you can use that *)
(* line 15 can't be rewritten like that.
I'm still trying to come up with another solution, but it's really different from the other two *)
(* line 16 *)
List.map (fun (vx, vy) -> atan2 (float_of_int vy) (float_of_int vx))
(* ...turns into... *)
List.map (uncurry (on atan2 float_of_int))
(* line 19 *)
List.sort (fun (_, a1) (_, a2) -> compare a1 a2)
(* ...turns into... *)
List.sort (uncurry (on compare snd))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment