Accessors.jl icon indicating copy to clipboard operation
Accessors.jl copied to clipboard

`obj` position in argument order

Open jariji opened this issue 1 year ago • 1 comments

Higher-order functions like map(f, obj) usually put the data argument last. In Accessors, it's usually hof(obj, optic, val) or modify(f, obj, optic) where the data argument comes earlier, which I didn't expect. I'm interested what explains this decision?

jariji avatar Jun 20 '24 21:06 jariji

In very early Setfield.jl commits the order was actually like you suggested. However:

  • I found it confusing that the order is switched in @set obj.field = val and set(@lens(_.field), obj, val)
  • There is one good reason to put functions first, namely do blocks. However, this advantage is lost if the first argument is an optic.
  • Also back in the day I missed/did not take seriously enough the viewpoint, that a lens is just a function that has a set method as well.

jw3126 avatar Jun 21 '24 05:06 jw3126

This does bother me a bit. I always expect it to be

modify(cumsum, reverse, xs)

like all the other functional programming things and I have to check the docs to remember that the optic comes last and the data comes in the middle. I'm happy with the function coming first.

jariji avatar Mar 12 '25 21:03 jariji

I personally also find the current order totally reasonable. Anyway, there's probably no objective better/worse here, and it's not worth a breaking change.

aplavin avatar Aug 05 '25 05:08 aplavin