Combine the functionality and operator Pipeline in F #

I am working on a project and I want to create a really compact method for creating entities and attributes.

I want to do this using a pipeline operator. But I want to add additional features to this operator.

Such as:

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

In this example | → would be a pipeline operator along with functionality to add an attribute to an entity.

I know this works:

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

So I want to know if you can replace

 |> addAttr 

from

 |>> 

thanks for the help

(I don't know if this is possible)

+6
source share
2 answers

You can simply define it like this:

 let (|>>) ea = e |> addAttr a 
+9
source

For readability, I would strongly refuse to add custom statements when a simple function is executed. You can change the way addAttr to make it easier to use in the pipeline:

 let addAttr name attrType entity = () // return an updated entity let e = entity "name" |> addAttr "attr" String |> addAttr "two" String 
+4
source

Source: https://habr.com/ru/post/1012108/


All Articles