Option
Table of Contents
Classes
Enums
Functions
- some() : Some<string|int, T>
- Return a `Option\Some` option containing `$value`.
- none() : None
- Return a `Option\None` option containing no values.
- fromValue() : NoneValue>)
- Transform a value into an `Option`.
- of() : NoneValue>)
- Execute a callable and transform the result into an `Option`.
- tryOf() : NoneValue>)
- Execute a callable and transform the result into an `Option` as `Option\of()` does but also return `Option\None` if it an exception matching $exceptionClass was thrown.
- flatten() : Option<string|int, U>
- Converts from `Option<Option<T>>` to `Option<T>`.
- transpose() : Result<Option<string|int, U>, E>
- Transposes an `Option` of a `Result` into a `Result` of an `Option`.
Functions
some()
Return a `Option\Some` option containing `$value`.
some(T $value) : Some<string|int, T>
Parameters
- $value : T
Tags
Return values
Some<string|int, T>none()
Return a `Option\None` option containing no values.
none() : None
Return values
NonefromValue()
Transform a value into an `Option`.
fromValue(U $value[, NoneValue|null $noneValue = null ]) : NoneValue>)
It will be a Some option containing $value if $value is different from $noneValue (default null)
Parameters
- $value : U
- $noneValue : NoneValue|null = null
Tags
Return values
NoneValue>)of()
Execute a callable and transform the result into an `Option`.
of(callable(): U $callback[, NoneValue|null $noneValue = null ]) : NoneValue>)
It will be a Some option containing the result if it is different from $noneValue (default null).
Parameters
- $callback : callable(): U
- $noneValue : NoneValue|null = null
Tags
Return values
NoneValue>)tryOf()
Execute a callable and transform the result into an `Option` as `Option\of()` does but also return `Option\None` if it an exception matching $exceptionClass was thrown.
tryOf(callable(): U $callback[, NoneValue|null $noneValue = null ][, E> $exceptionClass = Exception::class ]) : NoneValue>)
Parameters
- $callback : callable(): U
- $noneValue : NoneValue|null = null
- $exceptionClass : E> = Exception::class
Tags
Return values
NoneValue>)flatten()
Converts from `Option<Option<T>>` to `Option<T>`.
flatten(Option<string|int, Option<string|int, U>> $option) : Option<string|int, U>
Parameters
Tags
Return values
Option<string|int, U>transpose()
Transposes an `Option` of a `Result` into a `Result` of an `Option`.
transpose(Option<string|int, Result<U, E>> $option) : Result<Option<string|int, U>, E>
None will be mapped to Ok(None).
Some(Ok(_)) and Some(Err(_)) will be mapped to Ok(Some(_)) and Err(_).