Deedle icon indicating copy to clipboard operation
Deedle copied to clipboard

Make $ operator work on frames

Open hmansell opened this issue 11 years ago • 7 comments

hmansell avatar Nov 14 '13 16:11 hmansell

I was surprised when i saw this operator in the library. Why is it there? It feels the wrong way around for F#?

thanks don

ghost avatar Nov 14 '13 22:11 ghost

In case it is not obvious, it is not the same as the Haskell $ operator. It applies a function to a series, which is an extremely common operation. Having something more concise than Series.mapValues f is useful. I would also be happy with "series $> f" or "f <$ series", making it more consistent with existing pipeline operators.

hmansell avatar Nov 15 '13 00:11 hmansell

Is this even F# compatible?

s $> f

error FS0035: This construct is deprecated: '$' is not permitted as a character in operator names and is reserved for future use

adamklein avatar Nov 15 '13 17:11 adamklein

No, it's not possible to use $>.

ghost avatar Nov 15 '13 17:11 ghost

So $ is valid but $> is not?

On Fri, Nov 15, 2013 at 12:49 PM, Don Syme [email protected] wrote:

No, it's not possible to use $>.

— Reply to this email directly or view it on GitHubhttps://github.com/BlueMountainCapital/Deedle/issues/68#issuecomment-28588897 .

hmansell avatar Nov 15 '13 18:11 hmansell

I always complain when people use custom operators in their F# libraries, so I'm probably the last person who would add operator like this to a library, but - I added this as an experiment when going through some research code at BMC that did heavy mapping over time series and it made the code much nicer.

I mind operators less if they are just an alternative to function:

// You can just use 
ts |> Series.map foo

// And when you know the operator, you can use shorter
foo $ ts

I do not think this should be used with lambdas on left hand side - in that case, I'd always go with ordinary pipeline and mapValues and that's also why I did not add $> and <$ (and also, these are not above my personal bare for "nice operators" - but if others like them, that's ok..)

I think of it as "point-wise application" and that seems to be fairly reasonable use.

(More generally, this could also work on lists, sequences, etc., assuming that's technically possible)

tpetricek avatar Nov 15 '13 19:11 tpetricek

(The overloading might be doable using this crazy hack)

tpetricek avatar Nov 15 '13 19:11 tpetricek