add setFunctionArgs
This commit is contained in:
parent
2613fed53e
commit
1462db9587
|
@ -96,6 +96,34 @@ let
|
|||
then f.__functionArgs or (functionArgs (f.__functor 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
|
||||
like `builtins.trace`, but requires a string message and formats it as a
|
||||
|
@ -126,9 +154,10 @@ let
|
|||
else msg: builtins.trace "[1;31mwarning: ${msg}[0m";
|
||||
in
|
||||
{
|
||||
loadStatic = loadStatic;
|
||||
foldr = foldr;
|
||||
isFunction = isFunction;
|
||||
functionArgs = functionArgs;
|
||||
warn = warn;
|
||||
loadStatic = loadStatic;
|
||||
foldr = foldr;
|
||||
isFunction = isFunction;
|
||||
functionArgs = functionArgs;
|
||||
setFunctionArgs = setFunctionArgs;
|
||||
warn = warn;
|
||||
}
|
Loading…
Reference in a new issue