export unwrapMaybe, unwrapSome, unwrapNone in tests/maybe.nix

NOTE: nix-unit does NOT handle lambda partial equality well...
This commit is contained in:
Emile Clark-Boman 2026-01-28 09:15:49 +10:00
parent c84d84231b
commit 9db1e24987
2 changed files with 16 additions and 13 deletions

View file

@ -21,9 +21,8 @@ in {
inherit inherit
(maybe-mod) (maybe-mod)
Maybe unwrapSome
Some Some
None
; ;
in { in {
expr = Some true; expr = Some true;
@ -33,9 +32,7 @@ in {
derive = ["nt::&Maybe"]; derive = ["nt::&Maybe"];
instance = true; instance = true;
ops = { ops = {
"nt::&Maybe" = { "nt::&Maybe".unwrap = unwrapSome;
unwrap = f: self: f self.${bootstrap.ntDynamicTrapdoorKey}.value;
};
}; };
req = {}; req = {};
sig = "nt::Some"; sig = "nt::Some";

View file

@ -16,7 +16,13 @@
mkTrapdoorSet mkTrapdoorSet
openTrapdoor 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: Maybe is used to simplify parsing Type/Class declarations
# NOTE: and therefore must be implemented manually # NOTE: and therefore must be implemented manually
Maybe = let Maybe = let
@ -29,9 +35,7 @@ in {
in in
mkTrapdoorFn { mkTrapdoorFn {
default = { default = {
unwrap = T: unwrap = unwrapMaybe;
assert enfImpls "nt::&Maybe" T "nt::&Maybe.unwrap";
(T |> openTrapdoor ntTrapdoorKey).ops."nt::&Maybe".unwrap;
}; };
unlock.${ntTrapdoorKey} = meta false; unlock.${ntTrapdoorKey} = meta false;
}; };
@ -42,7 +46,7 @@ in {
sig = "nt::Some"; sig = "nt::Some";
derive = ["nt::&Maybe"]; derive = ["nt::&Maybe"];
ops = { ops = {
"nt::&Maybe".unwrap = f: self: f self.${ntDynamicTrapdoorKey}.value; "nt::&Maybe".unwrap = unwrapSome;
}; };
req = {}; req = {};
}; };
@ -67,15 +71,17 @@ in {
sig = "nt::None"; sig = "nt::None";
derive = ["nt::&Maybe"]; derive = ["nt::&Maybe"];
ops = { ops = {
"nt::&Maybe".map = f: self: self; "nt::&Maybe".unwrap = unwrapNone;
}; };
req = {}; req = {};
}; };
in in
mkTrapdoorFn { mkTrapdoorFn {
default = mkTrapdoorSet ntTrapdoorKey { default = mkTrapdoorSet {
default = {}; default = {};
unlock = meta true; unlock = {
${ntTrapdoorKey} = meta true;
};
}; };
unlock.${ntTrapdoorKey} = meta false; unlock.${ntTrapdoorKey} = meta false;
}; };