PHP Monad API Reference

Ok
in package
implements Result

Read onlyYes
FinalYes
Tags
template
implements

Table of Contents

Interfaces

Result
Result monad as a `Either monad`.

Methods

and()  : Result<U, E>
andThen()  : E>)
NOTE: PHPdoc's completion by type specification in Closure doesn't work, so I'm redefining it.
err()  : Option<string|int, E>
expect()  : T
getIterator()  : Traversable
inspect()  : $this
inspectErr()  : $this
isErr()  : false
isErrAnd()  : false
isOk()  : true
isOkAnd()  : bool
map()  : U>
mapErr()  : $this
mapOr()  : U
mapOrElse()  : U
match()  : U|V
Applies one of two functions depending on whether the result is Ok or Err.
ok()  : Some<string|int, T>
or()  : $this
orElse()  : $this
orThrow()  : $this
Returns the contained Ok value or throws the provided exception.
unwrap()  : T
unwrapErr()  : E
unwrapOr()  : T|U
unwrapOrElse()  : T|U
unwrapOrThrow()  : T
Returns the contained Ok value or throws the provided exception.

Methods

andThen()

NOTE: PHPdoc's completion by type specification in Closure doesn't work, so I'm redefining it.

public andThen(Closure $right) : E>)
Parameters
$right : Closure
Tags
phpstan-ignore

method.childParameterType

Attributes
#[Override]
Return values
E>)

err()

public err() : Option<string|int, E>
Attributes
#[Override]
Return values
Option<string|int, E>

expect()

public expect(string $message) : T
Parameters
$message : string
Attributes
#[Override]
Return values
T

getIterator()

public getIterator() : Traversable
Attributes
#[Override]
Return values
Traversable

inspect()

public inspect(Closure $callback) : $this
Parameters
$callback : Closure
Attributes
#[Override]
Return values
$this

inspectErr()

public inspectErr(Closure $callback) : $this
Parameters
$callback : Closure
Attributes
#[Override]
Return values
$this

isErr()

public isErr() : false
Attributes
#[Override]
Return values
false

isErrAnd()

public isErrAnd(Closure $predicate) : false
Parameters
$predicate : Closure
Attributes
#[Override]
Return values
false

isOk()

public isOk() : true
Attributes
#[Override]
Return values
true

isOkAnd()

public isOkAnd(Closure $predicate) : bool
Parameters
$predicate : Closure
Attributes
#[Override]
Return values
bool

map()

public map(callable(T): U $callback) : U>
Parameters
$callback : callable(T): U
Tags
template
Attributes
#[Override]
Return values
U>

mapErr()

public mapErr(Closure $callback) : $this
Parameters
$callback : Closure
Attributes
#[Override]
Return values
$this

mapOr()

public mapOr(Closure $callback, mixed $default) : U
Parameters
$callback : Closure
$default : mixed
Attributes
#[Override]
Return values
U

mapOrElse()

public mapOrElse(Closure $callback, Closure $default) : U
Parameters
$callback : Closure
$default : Closure
Attributes
#[Override]
Return values
U

match()

Applies one of two functions depending on whether the result is Ok or Err.

public match(Closure $okFn, Closure $errFn) : U|V

Comparable to neverthrow's match method.

Parameters
$okFn : Closure

Function to apply if the Result is Ok

$errFn : Closure

Function to apply if the Result is Err

Attributes
#[Override]
Return values
U|V

The result of applying the appropriate function

ok()

public ok() : Some<string|int, T>
Attributes
#[Override]
Return values
Some<string|int, T>

or()

public or(Result $right) : $this
Parameters
$right : Result
Attributes
#[Override]
Return values
$this

orElse()

public orElse(Closure $right) : $this
Parameters
$right : Closure
Attributes
#[Override]
Return values
$this

orThrow()

Returns the contained Ok value or throws the provided exception.

public orThrow(Throwable $exception) : $this
Parameters
$exception : Throwable

The exception to throw if the result is Err

Tags
template
throws
never
Attributes
#[Override]
Return values
$this

unwrap()

public unwrap() : T
Attributes
#[NoDiscard]
#[Override]
Return values
T

unwrapErr()

public unwrapErr() : E
Tags
throws
RuntimeException
Attributes
#[Override]
Return values
E

unwrapOr()

public unwrapOr(mixed $default) : T|U
Parameters
$default : mixed
Attributes
#[NoDiscard]
#[Override]
Return values
T|U

unwrapOrElse()

public unwrapOrElse(Closure $default) : T|U
Parameters
$default : Closure
Attributes
#[NoDiscard]
#[Override]
Return values
T|U

unwrapOrThrow()

Returns the contained Ok value or throws the provided exception.

public unwrapOrThrow(F $exception) : T
Parameters
$exception : F
Tags
template
throws
never
Attributes
#[NoDiscard]
#[Override]
Return values
T

        
On this page

Search results