From d7f0c3d171eec868a8c13bed2e076c65cbfbaabe Mon Sep 17 00:00:00 2001 From: tv Date: Sat, 17 Oct 2015 07:35:21 +0200 Subject: move maybe to krebs lib --- krebs/4lib/maybe.nix | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 krebs/4lib/maybe.nix (limited to 'krebs') 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); +} -- cgit v1.2.3