-
Notifications
You must be signed in to change notification settings - Fork 17
Description
apply_where is one of a relatively small subset of functions1 that accept a callable f and args and does something useful to the elements of args before passing them to f . If the user's callable f accepts keyword-only arguments, say kwargs, it is still possible to pass kwargs.values() as the args argument of apply_where, then as the callable(s) f1 (and f2, if applicable) something like lambda *args: f(dict(zip(kwargs.keys(), args))). This is somewhat cumbersome and hard to read, so I'd suggest that apply_where accept kwargs natively.
Footnotes
-
I call this out to distinguish
apply_wherefrom the many functions in the scientific Python ecosystem (or at least in SciPy) that accept a callablefalso acceptargs- only to pass them unmodified tof. IMO, this sort of "convenience" behavior bloats API, since it leads users to expect that all functions that accept callables should also acceptargs. Then, the natural extension of that expectation is for all these functions to also acceptkwargs. This is all unnecessary, since the user could have simply passedlambda x: f(x, *args, **kwargs)(orfwrapped withfunctools.partial) as the callable instead off, which is approximately as concise and readable. (It would be considered even more readable if it were the only option and universal practice.) ↩