lib: add lazy functor

This commit is contained in:
Infinidoge 2024-05-05 00:47:56 -04:00
parent 749ccedb6a
commit 89a55b45be
Signed by: Infinidoge
SSH key fingerprint: SHA256:oAMyvotlNFraMmZmr+p6AxnNfW/GioTs1pOn3V4tQ7A

View file

@ -48,6 +48,17 @@ rec {
};
spread = function: list: if list == [ ] then function else spread (function (head list)) (tail list);
# Takes a function and makes it lazy, by consuming arguments and applying it to the inner function first
# before calling the original function
lazy = func: inner: {
inherit func;
app = inner;
__functor = self: input:
let app = self.app input; in
if (typeOf app) == "lambda" then self // { inherit app; }
else self.func app;
};
} // (
import ./digga.nix { inherit lib; }
) // (