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 || isFunction = f: builtins.isFunction f ||
(f ? __functor && isFunction (f.__functor 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 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
@ -110,5 +129,6 @@ in
loadStatic = loadStatic; loadStatic = loadStatic;
foldr = foldr; foldr = foldr;
isFunction = isFunction; isFunction = isFunction;
functionArgs = functionArgs;
warn = warn; warn = warn;
} }