The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

fanderlf (2) [Avatar] Offline
#1
Hey there smilie

I'm new to F# and currently working through this book. I really like F# smilie

I've just got a little question. This function (Listing 6.4)

let mapSecond f (a, b) = (a, f(b))

I understand what it does, but I don't understand this usage:

oldPrague |> mapSecond ((+) 13195)

One chapter before the author wrote that I can use the pipeling operator to write the first parameter before the function name. But in this example the first parameter is the function.

((+) 13195) |> mapSecond oldPrague

didn't work. Does anybody have an explanation for me?

Thanks in advance!!!

Greetings
fanderlf
fanderlf (2) [Avatar] Offline
#2
Re: Why does pipelining work in Listing 6.5?
aaaaaaaaaaaaah smilie

After a little surfing on the INet I found this little link:

http://stevehorsfield.wordpress.com/2009/08/24/f-composing-functions/

For my example this means:

basic function:
let mapSecond f (a, b) = (a, f(b))

usage:
oldPrague |> mapSecond ((+) 13195)

The principle here is currying, as you can read in the book. So I think one could rewrite it with:

let mapSecondCurried = mapSecond ((+) 13195)
let newPrague = oldPrague |> mapSecondCurried

I hope this is write and that I got the problem smilie Maybe this helps somebody else, too. Perhaps the author could drop a little comment on that in the book. It wasn't obvious to me.

Greetings,
fanderlf