Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Function Application Operator ($) in F#?

Let's say I have this code

let identifier = spaces_surrounded (many1Satisfy isLetter)

I was wondering if it there was any native F# function that allowed me to refactor it to

let identifier = spaces_surrounded $ many1Satisfy isLetter

that is, something such as

let ($) f1 f2 = f1 (f2)

(that is if I am not mistaken, my Haskell skills are not too sharp..).

like image 358
devoured elysium Avatar asked Aug 25 '11 00:08

devoured elysium


1 Answers

The standard F# idiom for this is the forward pipe operator |> were you would rewrite

let identifier = spaces_surrounded (many1Satisfy isLetter)

as

let identifier = many1Satisfy isLetter |> spaces_surrounded 

you can also use the backward pipe operator <| if you want to maintain the original order, but this tends to be a little less common

let identifier = spaces_surrounded <| many1Satisfy isLetter
like image 51
John Palmer Avatar answered Oct 17 '22 21:10

John Palmer