On this page:
nothing
nothing?
just
just?
just-value
maybe?
maybe/  c
maybe-bind
maybe-map
maybe-if

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.

syntax

nothing

syntax

(nothing)

match expander

(nothing)

procedure

(nothing? v)  boolean?

  v : any/c
Struct-like operations which construct and deconstruct a maybe value that does not contain an element.

Every two nothing values are equal?.

syntax

just

syntax

(just value-expr)

match expander

(just value-pat)

procedure

(just? v)  boolean?

  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.

procedure

(maybe? v)  boolean?

  v : any/c
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.

procedure

(maybe/c c)  contract?

  c : contract?
Returns a contract that recognizes a maybe value where the element, if any, abides by the given contract.

procedure

(maybe-bind m func)  maybe?

  m : maybe?
  func : (-> any/c maybe?)
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.

procedure

(maybe-map m func)  maybe?

  m : maybe?
  func : (-> any/c any/c)
Creates a maybe value by replacing the element of the given maybe value, if any, with another according to the given function.

procedure

(maybe-if condition get-value)  maybe?

  condition : any/c
  get-value : (-> any/c)
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.