summaryrefslogtreecommitdiffstats
path: root/krebs
diff options
context:
space:
mode:
Diffstat (limited to 'krebs')
-rw-r--r--krebs/4lib/maybe.nix10
1 files changed, 10 insertions, 0 deletions
diff --git a/krebs/4lib/maybe.nix b/krebs/4lib/maybe.nix
new file mode 100644
index 000000000..5189c99a1
--- /dev/null
+++ b/krebs/4lib/maybe.nix
@@ -0,0 +1,10 @@
+{ ... }:
+
+rec {
+ Just = x: { type = "maybe"; value = x; };
+ Nothing = { type = "maybe"; };
+ isMaybe = x: builtins.typeOf x == "set" && x.type or false == "maybe";
+ isJust = x: isMaybe x && builtins.hasAttr "value" x;
+ fromJust = x: assert isJust x; x.value;
+ catMaybes = xs: map fromJust (builtins.filter isJust xs);
+}