BrechtL
BrechtL

Reputation: 127

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)

Upvotes: 6

Views: 107

Answers (2)

TheQuickBrownFox
TheQuickBrownFox

Reputation: 10624

For readability, I would strongly discourage adding custom operators when a simple function will do. You could change the way addAttr is written to make it easier to use in a pipeline:

let addAttr name attrType entity = () // return an updated entity

let e =
    entity "name"
    |> addAttr "attr" String
    |> addAttr "two"  String

Upvotes: 4

Tarmil
Tarmil

Reputation: 11362

You can simply define it like this:

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

Upvotes: 9

Related Questions