PHP Monad API Reference

Option extends Monad

Option monad as a `Maybe monad`.

Inspired by Rust's Option enum.

Tags
see
https://doc.rust-lang.org/std/option/enum.Option.html
template
extends
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

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
template
throws
F
Return values
$this

unit()

`return` in Haskell. (`Unit` operation.)

public static unit(TValue $value) : Monad<string|int, TValue>
Parameters
$value : TValue
Tags
template
Return values
Monad<string|int, TValue>

unwrapOrThrow()

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
template
throws
E
Return values
T

        
On this page

Search results