You won't be able to get exactly what you want, because of how tightly application binds relative to the precedence of operators. If you have "x op f y", this will be parsed as "x op (f y)", which will apply f to y before your operator gets a chance to do anything. There are two possible solutions to your problem. One would be to create a unary operator (or just a plain function) that flips the order of parameters to a function, like

1
let (~~) f x y = f y x

in which case you can do:

1
7 |> (~~ (%)) 5

The operator shouldn't need to be inlined, since it's truly generic.

The other alternative is to parenthesize things differently, but this may get really ugly in a long chain of pipes:

1
(7 |> (%)) 5
By on 2/23/2009 3:04 PM ()

One way to pipeline to parameters other than the last parameter is to pipe it to an anonymous function to reorder the variables for you.

For example:

1
2
3
let func x y z = ()

"hello" |> (fun str -> func 1 str 2)

In reality it doesn't matter which argument the pipeline operator ends up piping to, there will always be a case where you want to pipe parameters into some other argument, and you'll have to end up using this technique anyway.

Your example about subtraction by 48 could then be written like this:

1
2
3
code 
   |> Array.of_seq 
   |> Array.map (int >> (fun x -> 48 - x))
By on 2/23/2009 1:59 PM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper