How to make this F # code more compact

I want to go from:

let a = fun x ->
        x
        |> f
        |> g

      

like that:

let a = |> f
        |> g

      

I tried:

let a = (<|)  f 
              |> g

      

and similars

+3


source to share


1 answer


let a = fun x -> x |> f |> g

      

equivalent to

let a x = x |> f |> g

      

It sounds like you want to create two functions f

and g

to create a new function a

. You can use operator >>

to create functions. You can write:



let a = f >> g

      

If f

they g

are generic functions, they will not compile due to the limitations of F # values . In this case, you need to add type annotations:

let a<'a> : ('a -> 'a) = f >> g

      

+7


source







All Articles