move maybe to krebs lib

This commit is contained in:
tv 2015-10-17 07:35:21 +02:00
parent aa094e2b81
commit d7f0c3d171
2 changed files with 12 additions and 8 deletions

View File

@ -7,6 +7,8 @@ assert current-user-name != "";
let
lib = import <nixpkgs/lib>;
klib = import ./krebs/4lib { inherit lib; };
in with klib; let
nspath = ns: p: ./. + "/${ns}/${p}";
kpath = nspath "krebs";
@ -67,12 +69,4 @@ let
}.${v} or Nothing)
(builtins.readDir path)));
# TODO move to lib
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);
in out

10
krebs/4lib/maybe.nix Normal file
View File

@ -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);
}