We also have opportunity to use some function composition here, which lends us to partial application, and allow us to not care about the node parameter to our functions.
For example, we can take your titleText
and descriptionText
functions and simply omit the node
parameter and our functions still work the same, thus leaving them agnostic to what's applied even moreso than they were. But what if we want to omit node from elementAsDateTimeOffset
? Well we can't really do that as it's written, because the pipe-right (|>
) operator expects a value, not a function. Now we can use the compose-right (>>
) operator to eliminate that requirement:
let titleText =
innerText "title"
let descriptionText =
innerText "description"
let elementAsDateTimeOffset elementName =
innerText elementName >> DateTimeOffset.Parse
let elementAsUri elementName =
innerText elementName >> Uri
let linkUri =
elementAsUri "link"
Now here is the part I really like: none of our signatures changed, but we no longer care about the parameter itself in these functions. We've partially applied the functions. For example, on titleText
it is simply applying the "title"
string to the innerText
function (which expects two parameters) and returning a function that just needs an XmlNode
applied to it.
I like to use this more and more in my code as it seems a bit clearer to me in the end. The net result is the same, and there's no significant advantage (that I know of - do note I'm no expert) to using one over the other, but it becomes a preference on the developer's end. (This also lends itself very easily towards the introduction of currying: that is, every function has one and only one parameter, even those with multiple parameters.)