File tree Expand file tree Collapse file tree 1 file changed +7
-6
lines changed Expand file tree Collapse file tree 1 file changed +7
-6
lines changed Original file line number Diff line number Diff line change @@ -842,25 +842,26 @@ composeR f g x =
842
842
{- | Saying `x |> f` is exactly the same as `f x`.
843
843
844
844
It is called the “pipe” operator because it lets you write “pipelined” code.
845
- For example, say we have a `sanitize` function for turning user input in
846
- degrees into integers. We can rewrite it like this:
847
-
848
- import Maybe
845
+ For example, say we have a `sanitize` function for turning user input into
846
+ integers:
849
847
850
848
-- BEFORE
851
849
sanitize : String -> Maybe Int
852
850
sanitize input =
853
851
String.toInt (String.trim input)
854
852
853
+ We can rewrite it like this:
854
+
855
855
-- AFTER
856
856
sanitize : String -> Maybe Int
857
857
sanitize input =
858
858
input
859
859
|> String.trim
860
860
|> String.toInt
861
861
862
- To get a better intuition, I recommend trying to rewrite code that uses `x |> f`
863
- into code like `f x` until there are no pipes left.
862
+ Totally equivalent! I recommend trying to rewrite code that uses `x |> f`
863
+ into code like `f x` until there are no pipes left. That can help you build
864
+ your intuition.
864
865
865
866
**Note:** This can be overused! I think folks find it quite neat, but when you
866
867
have three or four steps, the code often gets clearer if you break out a
You can’t perform that action at this time.
0 commit comments