Search code examples
f#pipeline

Combine functionality and Pipeline operator in F#


I'm working on a project and I want to create a really compact method for creating Entities and Attributes.

I want to do this with the pipeline operator. But I want to add extra functionality to this operator.

Like for example :

let entity = (entity "name")
                 |>> (attribute "attr" String)
                 |>> (attribute "two"  String)

In this example |>> would be a pipeline operator together with the functionality to add an attribute to the entity.

I know that this works:

let entity = (entity "name")
             |> addAttr (attribute "attr" String)

So what I want to know is, if it's possible to replace

|> addAttr

with

|>> 

Thanks for the help

(I don't know if this is even possible)


Solution

  • You can simply define it like this:

    let (|>>) e a = e |> addAttr a