Hi,
I am toying with a module that end users are supposed to mainly be using via the Julia REPL, to leverage its piping capabilities.
In this specific tool’s REPL context, I would like to find a (somewhat safe, somewhat sanctionable) way to buccaneer map(f)
to make it currying (thus avoiding to introduce a new function+name for that purpose), i.e.,
[1,2,3] |> map(x->x^2)
should work. (This is unlikely to be done in Julia, as, unlike the upcoming filter
, corner cases of map’s current behavior exist.)
Any ideas would be much appreciated! Any other packages should be unaffected, as we want to avoid outright piracy. (Again, just the REPL use, the end user typing/memorizing experience, would be the goal here.)
My main two ideas would have been:
-
Somehow “un-export” Base.map from Main:
…but I found no way of removing the Main.map (alias?) from the (I suppose) “REPL module scope”Main
. -
Check for input argument count
I thought of overwriting the currentmap(f::Any)=f()
, and testing for number of arguments – then either follow the original map behavior for a function that has a method with 0 args (it would fail otherwise anyway), or simple curry. Still fiddling with that… maybe via thesig
field of all methods? (In this tool’s context, end users are highly unlikely to ever need or define zero-arg functions.)
(I am aware that even if a safe, REPL-only map-loot exists, that it might be considered dubious to “teach” non-standard map bahavior to users. In this specific case, end users are from a different profession, and unlikely to be exposed to this corner case map behavior in later/other Julia contexts.)
Thanks!
Martin