clean maybe.nix
This commit is contained in:
parent
79a6c6729b
commit
3c8ccea4a1
1 changed files with 7 additions and 4 deletions
|
|
@ -7,9 +7,7 @@
|
||||||
typeOf
|
typeOf
|
||||||
;
|
;
|
||||||
in rec {
|
in rec {
|
||||||
# NOTE: Maybe intentionally doesn't use the NixTypes.
|
# Naive Maybe Type
|
||||||
# NOTE: Maybe is used to aid in parsing and bootstrapping.
|
|
||||||
# NOTE: It is intentionally left simple for speed gains.
|
|
||||||
Maybe = some: value: {
|
Maybe = some: value: {
|
||||||
_some = some;
|
_some = some;
|
||||||
_value = value;
|
_value = value;
|
||||||
|
|
@ -19,6 +17,10 @@ in rec {
|
||||||
|
|
||||||
# Type Checking
|
# Type Checking
|
||||||
isMaybe = T: isAttrs T && attrNames T == ["_some" "_value"];
|
isMaybe = T: isAttrs T && attrNames T == ["_some" "_value"];
|
||||||
|
# XXX: TODO: make a pretty toString function
|
||||||
|
# XXX: TODO: make a pretty toString function
|
||||||
|
# XXX: TODO: make a pretty toString function
|
||||||
|
# XXX: TODO: make a pretty toString function
|
||||||
enfIsMaybe = T: msg: let
|
enfIsMaybe = T: msg: let
|
||||||
throw' = got: throw "${msg}: expected naive type Maybe but got ${got}";
|
throw' = got: throw "${msg}: expected naive type Maybe but got ${got}";
|
||||||
attrs =
|
attrs =
|
||||||
|
|
@ -47,7 +49,8 @@ in rec {
|
||||||
# Unwrap Operations
|
# Unwrap Operations
|
||||||
# Lift a value out of the monadic context.
|
# Lift a value out of the monadic context.
|
||||||
unwrapMaybe = T:
|
unwrapMaybe = T:
|
||||||
assert enfIsMaybe T "unwrapMaybe"; T._value;
|
assert enfIsMaybe T "unwrapMaybe";
|
||||||
|
T._value;
|
||||||
|
|
||||||
# Map Operations
|
# Map Operations
|
||||||
# Lift a value out of the monadic context and expect a new monadic.
|
# Lift a value out of the monadic context and expect a new monadic.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue