From 1462db958703232d4e029f0cca5b2a063bc56621 Mon Sep 17 00:00:00 2001 From: Jeff Hykin Date: Sat, 25 May 2024 12:26:31 -0400 Subject: [PATCH] add setFunctionArgs --- nodes/1_lib/source/detangled/1_foundation.nix | 39 ++++++++++++++++--- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/nodes/1_lib/source/detangled/1_foundation.nix b/nodes/1_lib/source/detangled/1_foundation.nix index 9ea0f88..735f03a 100644 --- a/nodes/1_lib/source/detangled/1_foundation.nix +++ b/nodes/1_lib/source/detangled/1_foundation.nix @@ -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 "warning: ${msg}"; in { - loadStatic = loadStatic; - foldr = foldr; - isFunction = isFunction; - functionArgs = functionArgs; - warn = warn; + loadStatic = loadStatic; + foldr = foldr; + isFunction = isFunction; + functionArgs = functionArgs; + setFunctionArgs = setFunctionArgs; + warn = warn; } \ No newline at end of file