3

I want to go from:

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

to something like this:

let a = |> f
        |> g

I tried:

let a = (<|)  f 
              |> g

and similars

Lay González
  • 2,901
  • 21
  • 41

1 Answers1

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

is equivalent to

let a x = x |> f |> g

It looks like you want to compose two functions f and g to create a new function a. You can use the >> operator to compose functions. You could write:

let a = f >> g

If f and g are generic functions then it will fail to compile due to F# value restrictions. In that case, you need to add type annotations:

let a<'a> : ('a -> 'a) = f >> g
  • There's a good general explaination of compose at [fsharpforfunandprofit.com](http://fsharpforfunandprofit.com/posts/function-composition/) – Jono Job Nov 28 '14 at 05:19