You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Once we get a splat operator, this functionality will be more useful, but a fun feature in Nix (cc @oconnorr) is the ability to ask a function about what arguments it takes (assuming it uses the attribute pattern matching construct). Given that jsonnet now has named arguments, it seems like a similar primop could work. I'd imagine it would tell you the number of positional arguments and the names of the attributes for named arguments. You could then use that to implement a form of pseudo-dependency-injection like the one we use in nixpkgs.
Ideal would be some way to access defaults as well. I could imagine that since you're lazy, you could have named return an actual object whose values reference the other arguments, but I don't know how that dict interacts with positional arguments today so it might be a little tricky.
P.S: the Haskeller in me is screaming at me for wanting such an obviously evil function but it does seem pretty handy.
The text was updated successfully, but these errors were encountered:
One use I have is for adding type/contract-checking wrappers around the arguments to a function. In practice, I already have the length of the list of contracts, so I can dispatch on that for all function of less than N arguments (with N=5) and error out if there are too many arguments. A bit ugly, though.
Once we get a splat operator, this functionality will be more useful, but a fun feature in Nix (cc @oconnorr) is the ability to ask a function about what arguments it takes (assuming it uses the attribute pattern matching construct). Given that jsonnet now has named arguments, it seems like a similar primop could work. I'd imagine it would tell you the number of positional arguments and the names of the attributes for named arguments. You could then use that to implement a form of pseudo-dependency-injection like the one we use in nixpkgs.
So basically, what I imagine is something like:
Ideal would be some way to access defaults as well. I could imagine that since you're lazy, you could have
named
return an actual object whose values reference the other arguments, but I don't know how that dict interacts with positional arguments today so it might be a little tricky.P.S: the Haskeller in me is screaming at me for wanting such an obviously evil function but it does seem pretty handy.
The text was updated successfully, but these errors were encountered: