Option
extends
Monad
in
Option monad as a `Maybe monad`.
Inspired by Rust's Option enum.
Tags
Attributes
- #[Sealed]
- $permits: [\WizDevelop\PhpMonad\Option\Some::class, \WizDevelop\PhpMonad\Option\None::class]
Table of Contents
Methods
- and() : Option<string|int, U>
- andThen() : Option<string|int, U>
- NOTE: PHPdoc's completion by type specification in Closure doesn't work, so I'm redefining it.
- expect() : T
- filter() : Option<string|int, T>
- inspect() : $this
- isNone() : bool
- isSome() : bool
- isSomeAnd() : bool
- map() : Option<string|int, U>
- mapOr() : U|V
- mapOrElse() : U|V
- okOr() : Result<T, E>
- okOrElse() : Result<T, E>
- or() : Option<string|int, T|U>
- orElse() : Option<string|int, T|U>
- orThrow() : $this
- Returns the contained Ok value or throws the provided exception.
- unit() : Monad<string|int, TValue>
- `return` in Haskell. (`Unit` operation.)
- unwrap() : T
- unwrapOr() : T|U
- unwrapOrElse() : T|U
- unwrapOrThrow() : T
- Returns the contained Some value or throws the provided exception.
- xor() : Option<string|int, T|U>
Methods
and()
public
and(Option<string|int, U> $right) : Option<string|int, U>
Parameters
- $right : Option<string|int, U>
Tags
Return values
Option<string|int, U>andThen()
NOTE: PHPdoc's completion by type specification in Closure doesn't work, so I'm redefining it.
public
andThen(callable(T): Option<string|int, U> $right) : Option<string|int, U>
Parameters
- $right : callable(T): Option<string|int, U>
Tags
Return values
Option<string|int, U>expect()
public
expect(string $message) : T
Parameters
- $message : string
Tags
Return values
Tfilter()
public
filter(callable(T): bool $predicate) : Option<string|int, T>
Parameters
- $predicate : callable(T): bool
Tags
Return values
Option<string|int, T>inspect()
public
inspect(callable(T): mixed $callback) : $this
Parameters
- $callback : callable(T): mixed
Tags
Return values
$thisisNone()
public
isNone() : bool
Tags
Return values
boolisSome()
public
isSome() : bool
Tags
Return values
boolisSomeAnd()
public
isSomeAnd(callable(T): bool $predicate) : bool
Parameters
- $predicate : callable(T): bool
Tags
Return values
boolmap()
public
map(callable(T): U $callback) : Option<string|int, U>
Parameters
- $callback : callable(T): U
Tags
Return values
Option<string|int, U>mapOr()
public
mapOr(callable(T): U $callback, V $default) : U|V
Parameters
- $callback : callable(T): U
- $default : V
Tags
Return values
U|VmapOrElse()
public
mapOrElse(callable(T): U $callback, callable(): V $default) : U|V
Parameters
- $callback : callable(T): U
- $default : callable(): V
Tags
Return values
U|VokOr()
public
okOr(E $err) : Result<T, E>
Parameters
- $err : E
Tags
Return values
Result<T, E>okOrElse()
public
okOrElse(callable(): E $err) : Result<T, E>
Parameters
- $err : callable(): E
Tags
Return values
Result<T, E>or()
public
or(Option<string|int, U> $right) : Option<string|int, T|U>
Parameters
- $right : Option<string|int, U>
Tags
Return values
Option<string|int, T|U>orElse()
public
orElse(callable(): Option<string|int, U> $right) : Option<string|int, T|U>
Parameters
- $right : callable(): Option<string|int, U>
Tags
Return values
Option<string|int, T|U>orThrow()
Returns the contained Ok value or throws the provided exception.
public
orThrow(F $exception) : $this
Parameters
- $exception : F
-
The exception to throw if the result is Err
Tags
Return values
$thisunit()
`return` in Haskell. (`Unit` operation.)
public
static unit(TValue $value) : Monad<string|int, TValue>
Parameters
- $value : TValue
Tags
Return values
Monad<string|int, TValue>unwrap()
public
unwrap() : T
Tags
Return values
TunwrapOr()
public
unwrapOr(U $default) : T|U
Parameters
- $default : U
Tags
Return values
T|UunwrapOrElse()
public
unwrapOrElse(callable(): U $default) : T|U
Parameters
- $default : callable(): U
Tags
Return values
T|UunwrapOrThrow()
Returns the contained Some value or throws the provided exception.
public
unwrapOrThrow(E $exception) : T
Parameters
- $exception : E
-
The exception to throw if the option is None
Tags
Return values
Txor()
public
xor(Option<string|int, U> $right) : Option<string|int, T|U>
Parameters
- $right : Option<string|int, U>