diff options
author | Robert Hensing <roberth@users.noreply.github.com> | 2022-03-24 17:01:47 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-24 17:01:47 +0100 |
commit | ce5a33e62bea14024af8bfad23b54c8848a89d9e (patch) | |
tree | 6b85cec1750e456d6f852cb3e0a07b4694414b1f /lib/trivial.nix | |
parent | 6ea8d5ee71793e236a19af3b5686a1ccdb0af3da (diff) | |
parent | 6c469679f6dea7f0cefafcac7e9d95b98bf8ff55 (diff) |
Merge pull request #164660 from ncfavier/tests-restrict-arguments
nixos/testing: restrict arguments to makeTest
Diffstat (limited to 'lib/trivial.nix')
-rw-r--r-- | lib/trivial.nix | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/trivial.nix b/lib/trivial.nix index 543680a10801f..18616a189c269 100644 --- a/lib/trivial.nix +++ b/lib/trivial.nix @@ -441,6 +441,25 @@ rec { isFunction = f: builtins.isFunction f || (f ? __functor && isFunction (f.__functor f)); + /* + Turns any non-callable values into constant functions. + Returns callable values as is. + + Example: + + nix-repl> lib.toFunction 1 2 + 1 + + nix-repl> lib.toFunction (x: x + 1) 2 + 3 + */ + toFunction = + # Any value + v: + if isFunction v + then v + else k: v; + /* Convert the given positive integer to a string of its hexadecimal representation. For example: |