On this page:
Maybe
Some
None
some
is-some?
is-none?
maybe?
maybe-bind
get-some
maybe-map
maybe-filter
maybe-guard

3.14 Maybe🔗ℹ

Maybe is an "option type", similar to that found in languages like Scala, Haskell, and Rust. It allows for safe return from a function that might not return a result, without relying on Null. A Maybe can be either a Some containing a value, or the empty thing None. Maybe is implemented as a heirarchy of things, and the usual thing functions and behaviors apply to them, but a number of helper functions have also been provided for easier use with them.

value

Maybe : thing? = (thing)

The parent object of the Maybe family.

value

Some : maybe? = (thing extends Maybe (contains Null))

The thing for a Maybe containing a value. Child of Maybe.

value

None : maybe? = (thing extends Maybe)

The empty value, for a Maybe that contains no value.

procedure

(some v)  is-some?

  v : any?
Returns v wrapped in Some.

procedure

(is-some? opt)  boolean?

  opt : any?
Returns True if opt is Some.

procedure

(is-none? opt)  boolean?

  opt : any?
Returns True if opt is None.

procedure

(maybe? opt)  boolean?

  opt : any?
Returns True if opt is a Maybe.

procedure

(maybe-bind opt fn)  (or is-none? any?)

  opt : maybe?
  fn : fn?
The bind operator for Maybe. Returns None if opt is None, or if it is Some, returns the result of fn applied to the value field of Some.

procedure

(get-some opt)  (or is-none? any?)

  opt : maybe?
If opt is Some, returns the value it contains, or else None.

procedure

(maybe-map fn opt)  maybe?

  fn : fn?
  opt : maybe?
Returns the result of fn applied to the value contained in opt.

procedure

(maybe-filter pred? opt)  maybe?

  pred? : fn?
  opt : maybe?
If pred? is true for the value contained in opt, returns opt, else returns None.

procedure

(maybe-guard test)  maybe?

  test : boolean?
The monad guard operator for maybe. If test is true, returns (some Null), else returns None.