From be2638f11b5c7efaf805a516fcb9534c61175a74 Mon Sep 17 00:00:00 2001 From: Infinidoge Date: Wed, 7 Feb 2024 11:22:53 -0500 Subject: [PATCH] lib: add recMap, chain, spread functions --- lib/default.nix | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib/default.nix b/lib/default.nix index 951e7bf..c758104 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -32,6 +32,22 @@ rec { lib.genAttrs list (name: func (if builtins.typeOf attrs == "lambda" then attrs name else attrs)); dirsOf = dir: lib.attrNames (lib.filterAttrs (file: type: type == "directory") (builtins.readDir dir)); + + # Only useful for functors + recMap = f: list: + if list == [ ] then f + else recMap (f (head list)) (tail list) + ; + + chain = { + func = id; + __functor = self: input: + if (typeOf input) == "lambda" + then self // { func = e: input (self.func e); } + else self.func input; + }; + + spread = function: list: if list == [ ] then function else spread (function (head list)) (tail list); } // ( import ./digga.nix { inherit lib; } ) // (