implement Terminal

This commit is contained in:
Emile Clark-Boman 2025-12-15 00:14:04 +10:00
parent ea01dcc827
commit 5da4058650
2 changed files with 23 additions and 0 deletions

View file

@ -2,10 +2,12 @@
fault = import ./fault.nix args;
maybe = import ./maybe.nix args;
res = import ./res.nix args;
terminal = import ./terminal.nix args;
in
nib.std.mergeAttrsList [
# submodule is included directly to this module (ie self.myFunc)
fault
maybe
res
terminal
]

21
nib/types/terminal.nix Normal file
View file

@ -0,0 +1,21 @@
{nib, ...}: rec {
# Terminal Monad
# Wrapper around a value (preserves lazy eval for the value)
Terminal = value: {
_nbtype_ = "nib::Terminal";
_value_ = value;
};
# Pattern Matching
isTerminal = T:
(builtins.attrNames T == ["_nbtype_" "_value_"])
&& T._nbtype_ == "nib::Terminal";
# Unwrap (Monadic Return Operation)
unwrapTerminal = T:
assert isTerminal T || nib.panic.badType "Terminal" T;
T._value_;
# Map (Monadic Bind Operation)
mapTerminal = f: T: Terminal (f (unwrapTerminal T));
}