by samdk · 14y ago · 0 comments
List.map data ~f:(fun elem -> ...)
|! List.find ~f:( ... )
|! Option.map ~f:( ... )
(This is OCaml, not Haskell, but the syntax is similar.) The definition of the '|!' operator is quite simple: let (|!) x f = f x (|>) :: a -> (a->b) -> b
(|>) x f = f x
infixl 0 |>
There infixl 0 means infix operator with left associativity and 0 precedence.Then you can use all sorts of expressions inbetween:
(5 + 3 |> show) ++ " times" |> putStrLn
Also, tying this back to one of the article's ideas, this piping-like syntax for doing things really manages to take away the emphasis from the function and put it back on the data. It isn't all about functions after all!Eg:
(reduce + (take 10 (filter even? (map #(* % %) (range)))))
Can be expressed as:
(->> (range)
(map #(* % %))
(filter even?)
(take 10)
(reduce +))