Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

flip arguments to Elm function call

Tags:

elm

I am trying to modify the Elm example that shows a single spacer so that it renders multiple spacers of different colors:

import Color exposing (red, blue, yellow)
import Graphics.Element exposing (Element, color, spacer, flow, right)


colors = [ yellow, red, blue ]

presentColors : List Element
presentColors = List.map (color ??? (spacer 30 30)) colors

main : Element
main =
  flow right presentColors

However as you can see the function color takes the color argument first and so I cannot create a partially applied version of it for List.map to use.

So how can I flip the arguments to color so that it can be partially applied?

like image 426
Terrence Brannon Avatar asked May 20 '15 15:05

Terrence Brannon


2 Answers

As of Elm 0.19, flip is no longer included by default. The docs recommend named helper functions instead.


Go to the Elm (pre v0.19) libraries page. Press Standard Libraries. In the search box, type in flip and click the function that comes up. That'll give you the documentation for

flip : (a -> b -> c) -> b -> a -> c
Flip the order of the first two arguments to a function.

With which you can do

flip color (spacer 30 30)

which is the same thing as

\c -> color c (spacer 30 30)
like image 91
kqr Avatar answered Oct 18 '22 23:10

kqr


Flip was removed from elm/core in 0.19. You could try:
pilatch/flip package instead.

like image 23
Memke Avatar answered Oct 18 '22 22:10

Memke