Trait Optpub

Source
:trait(pub) Opt
  .is-some ( (Option a) → Bool )
  .is-none ( (Option a) → Bool )
  .map ( [a → b ] (Option a) → (Option b) )
  .and-then ( [a → (Option b) ] (Option a) → (Option b) )
  .or-else ( [→ (Option a) ] (Option a) → (Option a) )
  .unwrap ( (Option a) → a )
  .expect ( (Option a) Str → a )
  .unwrap-or ( a (Option a) → a )
  .unwrap-or-else ( [→ a ] (Option a) → a )
  .filter ( [a → Bool ] (Option a) → (Option a) )
  .flatten ( (Option (Option a)) → (Option a) )
  .ok-or ( err (Option a) → (Result a err) )
  .ok-or-else ( (Option a) [→ err ] → (Result a err) )
  .map-or ( (Option a) b [a → b ] → b )
  .map-or-else ( (Option a) [→ b ] [a → b ] → b )
  .and ( (Option a) (Option b) → (Option b) )
  .take ( (Option a) → (Option a) (Option a) )
  .is-some-and ( (Option a) [a → Bool ] → Bool )
  .is-none-or ( (Option a) [a → Bool ] → Bool )
  .xor ( (Option a) (Option a) → (Option a) )
  .zip ( (Option a) (Option b) → (Option (Pair a b)) )
  .transpose ( (Option (Result a e)) → (Result (Option a) e) )
  .unzip ( (Option (Pair a b)) → (Option a) (Option b) )
  .zip-with ( (Option a) (Option b) [a b → c ] → (Option c) )
  .take-if ( (Option a) [a → Bool ] → (Option a) (Option a) )
  .inspect ( (Option a) [a → ] → (Option a) )
  .contains ( (Option a) a → Bool )
Description

Combinator surface on (Option a). Every method dispatches on the None/Some tag and delegates to a user-provided quotation for the Some case. Short-circuiting variants (.and-then, .or-else, .unwrap-or-else) only evaluate their quotation when the Option's tag selects that branch.

Required Methods

.is-some ( (Option a) → Bool )

True iff the Option carries a value.

.is-none ( (Option a) → Bool )

True iff the Option is None.

.map ( [a → b ] (Option a) → (Option b) )

Apply a function to the contained value, preserving the Some/None structure.

.and-then ( [a → (Option b) ] (Option a) → (Option b) )

Chain into another Option-producing computation (the monadic bind).

.or-else ( [→ (Option a) ] (Option a) → (Option a) )

Supply a replacement Option when the receiver is None.

.unwrap ( (Option a) → a )

Return the contained value, panicking if None.

.expect ( (Option a) Str → a )

Return the contained value, panicking with the supplied message if None.

.unwrap-or ( a (Option a) → a )

Return the contained value, or a fallback if None.

.unwrap-or-else ( [→ a ] (Option a) → a )

Return the contained value, or invoke a thunk to produce the fallback if None.

.filter ( [a → Bool ] (Option a) → (Option a) )

Keep the value iff it satisfies a predicate; otherwise become None.

.flatten ( (Option (Option a)) → (Option a) )

Collapse (Option (Option a)) into (Option a) by one layer.

.ok-or ( err (Option a) → (Result a err) )

Convert to a Result, supplying a fixed error value for the None case.

.ok-or-else ( (Option a) [→ err ] → (Result a err) )

Convert to a Result, invoking a thunk to produce the error for the None case.

.map-or ( (Option a) b [a → b ] → b )

.map-or-else ( (Option a) [→ b ] [a → b ] → b )

.and ( (Option a) (Option b) → (Option b) )

.take ( (Option a) → (Option a) (Option a) )

.is-some-and ( (Option a) [a → Bool ] → Bool )

.is-none-or ( (Option a) [a → Bool ] → Bool )

.xor ( (Option a) (Option a) → (Option a) )

.zip ( (Option a) (Option b) → (Option (Pair a b)) )

.transpose ( (Option (Result a e)) → (Result (Option a) e) )

.unzip ( (Option (Pair a b)) → (Option a) (Option b) )

.zip-with ( (Option a) (Option b) [a b → c ] → (Option c) )

.take-if ( (Option a) [a → Bool ] → (Option a) (Option a) )

.inspect ( (Option a) [a → ] → (Option a) )

Call a quotation on the inner value for side effects, returning the Option unchanged.

.contains ( (Option a) a → Bool )

True iff the Option is Some and the inner value equals the supplied argument.

Implementors

impl Opt for Option