add functionArgs

This commit is contained in:
Jeff Hykin 2024-05-25 12:22:03 -04:00
parent 415acdce94
commit 2613fed53e

View file

@ -77,6 +77,25 @@ let
isFunction = f: builtins.isFunction f ||
(f ? __functor && isFunction (f.__functor f));
/**
Extract the expected function arguments from a function.
This works both with nix-native { a, b ? foo, ... }: style
functions and functions with args set with 'setFunctionArgs'. It
has the same return type and semantics as builtins.functionArgs.
setFunctionArgs : (a b) Map String Bool.
# Inputs
`f`
: 1\. Function argument
*/
functionArgs = f:
if f ? __functor
then f.__functionArgs or (functionArgs (f.__functor f))
else builtins.functionArgs f;
/**
Print a warning before returning the second argument. This function behaves
like `builtins.trace`, but requires a string message and formats it as a
@ -107,8 +126,9 @@ let
else msg: builtins.trace "warning: ${msg}";
in
{
loadStatic = loadStatic;
foldr = foldr;
isFunction = isFunction;
warn = warn;
loadStatic = loadStatic;
foldr = foldr;
isFunction = isFunction;
functionArgs = functionArgs;
warn = warn;
}