Created
September 8, 2016 08:00
-
-
Save rohanorton/cebac1213db6ea17e2ab2897b3bd4082 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bang : String -> String | |
bang str = | |
str ++ “!” | |
uppercase : String -> String | |
uppercase str = | |
String.toUpper str | |
{-| Simple Function | |
in this function we're adding a couple of exclamation marks and | |
uppercasing as you can see, with all those parens it’s a bit noisy | |
-} | |
shout : String -> String | |
shout str = | |
uppercase (bang (bang str)) | |
{-| Returned Lambda Example | |
we can change it to return a new function instead using lambda | |
notation (anonymous function) this is even worse than previously | |
for noise, but sort of explains what is going to happen next | |
-} | |
shout': String -> String | |
shout' = | |
(\str -> uppercase(bang (bang str))) | |
{-| Function Composition Example | |
the above version essentially doing the same thing as this, | |
though now we don’t have the ugly floating variable or parens | |
-} | |
shout'' : String -> String | |
shout'' = | |
uppercase << bang << bang | |
{-| Pipe Syntax Example | |
elm also offers another nice way of composing functions into a | |
pipeline, which some people find easier to read as it more closely | |
resembles chaining in oop langauges like js and ruby, and also the | |
pipe operator `|` in shell scripting. | |
-} | |
shout''' : String -> String | |
shout''' str = | |
str | |
|> uppercase | |
|> bang | |
|> bang |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment