is that possible to pipe the first parameter into a multiple parameter function? for example
date = "20160301"
Is that possible to pipe date
into
DateTime.ParseExact( , "yyyyMMDD", CultureInfo.InvariantCulture)
As @yuyoyuppe explains in his/her answer, you can't pipe directly into ParseExact
because it's a method, and thereby not curried.
It's often a good option to define a curried Adapter function, but you can also pipe into an anonymous function if you only need it locally:
let res =
date |> (fun d -> DateTime.ParseExact(d, "yyyyMMdd", CultureInfo.InvariantCulture))
which gives you a DateTime
value:
> res;;
val it : DateTime = 01.03.2016 00:00:00
From this:
Methods usually use the tuple form of passing arguments. This achieves a clearer result from the perspective of other .NET languages because the tuple form matches the way arguments are passed in .NET methods.
Since you cannot curry a function which accepts tuple directly, you'll have to wrap the ParseExact
to do that:
let parseExact date = DateTime.ParseExact(date, "yyyyMMDD", CultureInfo.InvariantCulture)
Perhaps unrelated, but output arguments can be bound like that:
let success, value = Double.TryParse("2.5")
Note that TryParse
accepts the tuple with the second argument as byref
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With