stockholm/krebs/4lib/maybe.nix
2015-10-17 07:35:21 +02:00

11 lines
325 B
Nix

{ ... }:
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);
}