3 Maybe Values
(require lathe-comforts/maybe) | package: lathe-comforts-lib |
Maybe values are a way to encode optional data. Using maybe values can simplify some interfaces that would otherwise use run time errors or special-cased sentinel values like #f.
Struct-like operations which construct and deconstruct a maybe value that does not contain an element.
Every two nothing values are equal?.
syntax
syntax
(just value-expr)
match expander
(just value-pat)
procedure
v : any/c
procedure
(just-value inst) → any/c
inst : just?
Struct-like operations which construct and deconstruct a maybe value that contains an element.
Two just values are equal? if they contain equal? elements.
Returns whether the given value is a maybe value. That is, it checks that the value is either a nothing? value or a just? value.
Returns a contract that recognizes a maybe value where the element, if any, abides by the given contract.
Creates a maybe value by replacing the element of the given maybe value, if any, with zero or one elements according to the given function.
Creates a maybe value by replacing the element of the given maybe value, if any, with another according to the given function.
Creates a maybe value that has an element if and only if the given condition is not #f. The element is computed by calling the given function get-value with no arguments.