Created
March 25, 2018 22:50
-
-
Save FabioAntunes/4fab31ab14955549c47288a255e52e8d to your computer and use it in GitHub Desktop.
Example of Pipeline Operator proposal
This file contains 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
// Some functions that do string operations | |
function doubleSay (str) { | |
return str + ", " + str; | |
} | |
function capitalize (str) { | |
return str[0].toUpperCase() + str.substring(1); | |
} | |
function exclaim (str) { | |
return str + '!'; | |
} | |
// old way | |
let result = exclaim(capitalize(doubleSay("hello"))); | |
result //=> "Hello, hello!" | |
// with the new pipeline operator | |
let result = "hello" | |
|> doubleSay | |
|> capitalize | |
|> exclaim; | |
result //=> "Hello, hello!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment