diff options
author | tv <tv@shackspace.de> | 2015-10-17 07:35:21 +0200 |
---|---|---|
committer | tv <tv@shackspace.de> | 2015-10-17 07:35:21 +0200 |
commit | d7f0c3d171eec868a8c13bed2e076c65cbfbaabe (patch) | |
tree | 7d4bc2779eddbfe30a1e383d08450e138933bdba /krebs/4lib/maybe.nix | |
parent | aa094e2b81910455e2385c78727da13f03074913 (diff) |
move maybe to krebs lib
Diffstat (limited to 'krebs/4lib/maybe.nix')
-rw-r--r-- | krebs/4lib/maybe.nix | 10 |
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); +} |