my tech blog

To iterate is human, to recurse divine

Pipeline Operator in F#

First time I came in contact with a pipeline operator was on the linux command shell (bash) several years ago. It amazed me how powerful this little operator could be to compose more complicated commands.

The great thing is that there is a similar powerful operator available in F#, and you will see it appear often in F# code.

The pipeline operator looks like this in F#, |>, there are actually several other variants of the operator which we will see later. Here are some simple examples how to use it:

As I mentioned earlier there are other variants that we can use depending on our situation. We have, <|, ||>, <|| and more. Hopefully the examples below will clarify how they work.

F# is open source and the code is hosted on github, so we can dig into the code and see how these operators are implemented.

Here is the url to the repository: The file we are interested in is the prim-types.fs and is located in fsharp/src/fsharp/FSharp.Core directory, look around line 3492 to find the things we want.

Yes, it’s concise, beautiful and simple, as always in F# ;-)