export unwrapMaybe, unwrapSome, unwrapNone in tests/maybe.nix
NOTE: nix-unit does NOT handle lambda partial equality well...
This commit is contained in:
parent
c84d84231b
commit
9db1e24987
2 changed files with 16 additions and 13 deletions
|
|
@ -21,9 +21,8 @@ in {
|
|||
|
||||
inherit
|
||||
(maybe-mod)
|
||||
Maybe
|
||||
unwrapSome
|
||||
Some
|
||||
None
|
||||
;
|
||||
in {
|
||||
expr = Some true;
|
||||
|
|
@ -33,9 +32,7 @@ in {
|
|||
derive = ["nt::&Maybe"];
|
||||
instance = true;
|
||||
ops = {
|
||||
"nt::&Maybe" = {
|
||||
unwrap = f: self: f self.${bootstrap.ntDynamicTrapdoorKey}.value;
|
||||
};
|
||||
"nt::&Maybe".unwrap = unwrapSome;
|
||||
};
|
||||
req = {};
|
||||
sig = "nt::Some";
|
||||
|
|
|
|||
|
|
@ -16,7 +16,13 @@
|
|||
mkTrapdoorSet
|
||||
openTrapdoor
|
||||
;
|
||||
in {
|
||||
in rec {
|
||||
unwrapMaybe = f: self:
|
||||
assert enfImpls "nt::&Maybe" self "nt::&Maybe.unwrap";
|
||||
(self |> openTrapdoor ntTrapdoorKey).ops."nt::&Maybe".unwrap f self;
|
||||
unwrapSome = f: self: f (self |> openTrapdoor ntDynamicTrapdoorKey).value;
|
||||
unwrapNone = f: self: null;
|
||||
|
||||
# NOTE: Maybe is used to simplify parsing Type/Class declarations
|
||||
# NOTE: and therefore must be implemented manually
|
||||
Maybe = let
|
||||
|
|
@ -29,9 +35,7 @@ in {
|
|||
in
|
||||
mkTrapdoorFn {
|
||||
default = {
|
||||
unwrap = T:
|
||||
assert enfImpls "nt::&Maybe" T "nt::&Maybe.unwrap";
|
||||
(T |> openTrapdoor ntTrapdoorKey).ops."nt::&Maybe".unwrap;
|
||||
unwrap = unwrapMaybe;
|
||||
};
|
||||
unlock.${ntTrapdoorKey} = meta false;
|
||||
};
|
||||
|
|
@ -42,7 +46,7 @@ in {
|
|||
sig = "nt::Some";
|
||||
derive = ["nt::&Maybe"];
|
||||
ops = {
|
||||
"nt::&Maybe".unwrap = f: self: f self.${ntDynamicTrapdoorKey}.value;
|
||||
"nt::&Maybe".unwrap = unwrapSome;
|
||||
};
|
||||
req = {};
|
||||
};
|
||||
|
|
@ -67,15 +71,17 @@ in {
|
|||
sig = "nt::None";
|
||||
derive = ["nt::&Maybe"];
|
||||
ops = {
|
||||
"nt::&Maybe".map = f: self: self;
|
||||
"nt::&Maybe".unwrap = unwrapNone;
|
||||
};
|
||||
req = {};
|
||||
};
|
||||
in
|
||||
mkTrapdoorFn {
|
||||
default = mkTrapdoorSet ntTrapdoorKey {
|
||||
default = mkTrapdoorSet {
|
||||
default = {};
|
||||
unlock = meta true;
|
||||
unlock = {
|
||||
${ntTrapdoorKey} = meta true;
|
||||
};
|
||||
};
|
||||
unlock.${ntTrapdoorKey} = meta false;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue