From 9db1e2498708529912d8a6af610d05fdb51414b4 Mon Sep 17 00:00:00 2001 From: Emile Clark-Boman Date: Wed, 28 Jan 2026 09:15:49 +1000 Subject: [PATCH] export unwrapMaybe, unwrapSome, unwrapNone in tests/maybe.nix NOTE: nix-unit does NOT handle lambda partial equality well... --- tests/default.nix | 7 ++----- tests/maybe.nix | 22 ++++++++++++++-------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/tests/default.nix b/tests/default.nix index 2dcd883..b05db11 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -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"; diff --git a/tests/maybe.nix b/tests/maybe.nix index 0f5f8e6..d67c96a 100644 --- a/tests/maybe.nix +++ b/tests/maybe.nix @@ -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; };