PHP Monad API Reference

Err
in package
implements Result

Read onlyYes
FinalYes
Tags
template
implements

Table of Contents

Interfaces

Result
Result monad as a `Either monad`.

Methods

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

Methods

and()

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

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, missingType.generics

Attributes
#[Override]
Return values
E>)

err()

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

expect()

public expect(string $message) : T
Parameters
$message : string
Tags
throws
RuntimeException
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() : true
Attributes
#[Override]
Return values
true

isErrAnd()

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

isOk()

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

isOkAnd()

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

map()

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

mapErr()

public mapErr(callable(E): F $callback) : F>
Parameters
$callback : callable(E): F
Tags
template
Attributes
#[Override]
Return values
F>

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() : Option<string|int, T>
Attributes
#[Override]
Return values
Option<string|int, T>

orElse()

public orElse(Closure $right) : Result<T, F>
Parameters
$right : Closure
Attributes
#[Override]
Return values
Result<T, F>

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
F
Attributes
#[Override]
Return values
$this

unwrap()

public unwrap() : T
Tags
throws
Throwable
Attributes
#[Override]
Return values
T

unwrapErr()

public unwrapErr() : E
Attributes
#[NoDiscard]
#[Override]
Return values
E

unwrapOr()

public unwrapOr(U $default) : U
Parameters
$default : U
Tags
template
Attributes
#[NoDiscard]
#[Override]
Return values
U

unwrapOrElse()

public unwrapOrElse(callable(E): U $default) : U
Parameters
$default : callable(E): U
Tags
template
Attributes
#[NoDiscard]
#[Override]
Return values
U

unwrapOrThrow()

Returns the contained Ok value or throws the provided exception.

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

        
On this page

Search results