add setFunctionArgs

This commit is contained in:
Jeff Hykin 2024-05-25 12:26:31 -04:00
parent 2613fed53e
commit 1462db9587

View file

@ -96,6 +96,34 @@ let
then f.__functionArgs or (functionArgs (f.__functor f)) then f.__functionArgs or (functionArgs (f.__functor f))
else builtins.functionArgs f; else builtins.functionArgs f;
/**
Add metadata about expected function arguments to a function.
The metadata should match the format given by
builtins.functionArgs, i.e. a set from expected argument to a bool
representing whether that argument has a default or not.
setFunctionArgs : (a b) Map String Bool (a b)
This function is necessary because you can't dynamically create a
function of the { a, b ? foo, ... }: format, but some facilities
like callPackage expect to be able to query expected arguments.
# Inputs
`f`
: 1\. Function argument
`args`
: 2\. Function argument
*/
setFunctionArgs = f: args:
{
__functor = self: f;
__functionArgs = args;
};
/** /**
Print a warning before returning the second argument. This function behaves Print a warning before returning the second argument. This function behaves
like `builtins.trace`, but requires a string message and formats it as a like `builtins.trace`, but requires a string message and formats it as a
@ -130,5 +158,6 @@ in
foldr = foldr; foldr = foldr;
isFunction = isFunction; isFunction = isFunction;
functionArgs = functionArgs; functionArgs = functionArgs;
setFunctionArgs = setFunctionArgs;
warn = warn; warn = warn;
} }