Created
March 27, 2012 18:39
-
-
Save stefanalfbo/2218950 to your computer and use it in GitHub Desktop.
Simple examples of pipeline operator in F#
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 to play with | |
let double x = x * 2 | |
let triple x = x * 3 | |
let square x = x * x | |
// fsi | |
>2 |> double;; | |
val it : int 4 | |
let pipelining n = | |
n | |
|> double | |
|> triple | |
|> square | |
// fsi | |
> pipelining 10;; | |
val it : int = 3600 | |
// when a function takes more than one parameter | |
let subtract x y = y - x | |
// fsi | |
> subtract 2 4;; | |
val it : int = 2 | |
// here the 2 will bind to x and y to 4 | |
> 4 |> subtract 2;; | |
val it : int = 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment