From 0906cdb433fe5b8c67c2956c475a9b6d340a260f Mon Sep 17 00:00:00 2001 From: tv Date: Sat, 25 Jul 2015 02:14:44 +0200 Subject: {3 -> 4} krebs {listset,tree} --- 4lib/krebs/default.nix | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to '4lib') diff --git a/4lib/krebs/default.nix b/4lib/krebs/default.nix index 0c59076..0c42a5d 100644 --- a/4lib/krebs/default.nix +++ b/4lib/krebs/default.nix @@ -12,4 +12,22 @@ builtins // lib // rec { types = import ./types.nix { inherit lib; }; + + # listset k v = set k [v] + + # listset-insert : k -> v -> listset k v -> listset k v + listset-insert = name: value: set: + set // { ${name} = set.${name} or [] ++ [value]; }; + + # tree k v = set k (either v (tree k v)) + + # tree-get : [k] -> tree k v -> v + tree-get = path: x: + let + y = x.${last path}; + in + if typeOf y != "set" + then y + else tree-get (init path) y; + } -- cgit v1.2.3