I keep practicing my F# skills on Project Euler. While doing problem 19 (a drastic anticlimax after the cool problem 18) I found myself in need of performing a modulo 7 operation on a list of numbers. I tried this:
List.map ((%) 7)
And ended up with the wrong list of numbers. That’s because List.map binds the second argument, so instead of calculation n%7 it ended up calculating 7%n . Is there a way to make List.map bind the first argument, or a standard way of flipping the two arguments?
I know I can use a fun n->n%7 instead of (%) 7, but I was hoping for a shorter solution.
You can define
flipfor this purpose:This is a rather common way of doing this in functional programming languages. For example, Haskell also has a
flipfunction in its Prelude.