Is dollar operator ($) supported in elm?

In Haskell, you can use the $ operator to clear bits of code, eliminating the need for parens.

Does this operator support vli or something like that?

I can define it myself, but I was hoping that it was something built-in.

Here's how it works:

 import Html import List exposing (map, foldr) datas = [("a", 1), ("b", 2), ("c", 3)] {--} ($) : (a -> b) -> (a -> b) ($) ab = ab infixr 0 $ --} main = {-- replace all these parens Html.text (toString (foldr (++) "" (map fst datas))) --} Html.text $ toString $ foldr (++) "" $ map fst datas 
+7
functional-programming elm
source share
1 answer

Yes, we use <| instead of $ . We took it from F # along with a flip version |> and << for composition . and the inverted version >> .
Once they were introduced, people naturally gravitated towards a style called "pipelining", where you take some data and convert it into a couple of steps using the |> operator. This is more common Elm code these days than using <| .

For example:

 update : (Float, Keys) -> Model -> Model update (dt, keys) mario = mario |> gravity dt |> jump keys |> walk keys |> physics dt 

(Adapted from the example of Mario on the website )

+12
source share

All Articles