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
.map ( [a → b ] (Option a) → (Option b) )
.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) )
.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) )
.or-else ( [→ (Option a) ] (Option a) → (Option a) )
Supply a replacement Option when the receiver is None.
.expect ( (Option a) Str → a )
.expect ( (Option a) Str → a )
Return the contained value, panicking with the supplied message if None.
.unwrap-or-else ( [→ a ] (Option a) → a )
.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) )
.filter ( [a → Bool ] (Option a) → (Option a) )
Keep the value iff it satisfies a predicate; otherwise become None.
.flatten ( (Option (Option a)) → (Option a) )
.flatten ( (Option (Option a)) → (Option a) )
Collapse (Option (Option a)) into (Option a) by one layer.
.ok-or ( err (Option a) → (Result a err) )
.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) )
.ok-or-else ( (Option a) [→ err ] → (Result a err) )
Convert to a Result, invoking a thunk to produce the error for the None case.