Skip to content
This repository has been archived by the owner on Sep 26, 2024. It is now read-only.

Latest commit

 

History

History

docs

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 

Documentation

class Result<T,E>

Visibility Function
public static ok(T $value): Result<U,F>
Create an Ok result.
public static error(E $error): Result<U,F>
Create an error result.
public and(Result<U,E> $res): Result<U,E>
Returns res if the result is Ok, otherwise returns the Err value of self.
public andThen(\callable $op): Result<U,E>
Calls op if the result is Ok, otherwise returns the Err value of self.
public contains(T $value): void
Returns true if the result is an Ok value containing the given value (compared with ==).
public containsError(E $error): void
Returns true if the result is an error containing the given value (comapred with ==).
public containsSame(T $value): void
Returns true if the result is an Ok value containing the given value (compared with ===).
public containsSameError(E $error): void
Returns true if the result is an error containing the given value (comapred with ===).
public errorValue(): Option
Converts from Result<T,E> to Option, and discarding the Ok value, if any.
public expect(\string $errorMessage): T
Returns the contained Ok value or throws a ResultError with a custom message if result is an error
public expectError(\string $errorMessage): E
Returns the contained error value or throws a ResultError with a custom message if result is Ok
public flatten(): Result<T2,E>
Converts from Result<Result<T,E>,E> to Result<T,E>
public getIterator(): \Generator
public isError(): bool
Returns true if the result is an error.
public isOk(): bool
Returns true if the result is Ok.
public map(\callable $f): Result<U,E>
Maps a Result<T,E> to Result<U,E> by applying a function to a contained Ok value, leaving an Err value untouched.
public mapError(\callable $f): Result<T,F>
Maps a Result<T,E> to Result<T,F> by applying a function to a contained Err value, leaving an Ok value untouched.
public mapOr(\callable $f, U $default): U
Applies a function to the contained value (if Ok), or returns the provided default (if Err).
public mapOrElse(\callable $f, \callable $fallback): U
Maps a Result<T,E> to U by applying a function to a contained Ok value, or a fallback function to a contained Err value.
public okValue(): Option
Converts from Result<T,E> to Option, and discarding the error, if any.
public or(Result<U,E> $res): Result<U,E>
Returns res if the result is an error, otherwise returns the Ok value of self.
public orElse(\callable $op): Result<U,E>
Calls op if the result is an error, otherwise returns the Ok value of self.
public transpose(): Option
Transposes a Result of an Option into an Option of a Result.
public unwrap(): T
Returns the contained Ok value or throws a ResultError if result is an error
public unwrapError(): E
Returns the contained error value or throws a ResultError if result is an error
public unwrapOr(T $default): T
Returns the contained Ok value or a provided default.
public unwrapOrElse(\callable $f): T
Returns the contained Ok value or computes it from a closure.

This class implements \Traversable

class Option<T>

Visibility Function
public static some(T $value): Option
Create an option with a value
public static none(): Option
Create an empty Option
public and(Option $b): Option
Returns None if the option is None, otherwise returns option b.
public andThen(\callable $f): Option
Returns None if the option is None, otherwise calls f with the wrapped value and returns the result
public contains(T $value): void
Returns true if the option contains the given value (compared with ==)
public containsSame(T $value): void
Returns true if the option contains the given value (compared with ===)
public expect(\string $errorMessage): T
Returns the contained value or throws a NoneError with a custom message if empty
public expectNone(\string $errorMessage): void
Throws a NoneError with a custom message if not empty
public filter(\callable $p): Option
Returns None if the option is None, otherwise calls predicate with the wrapped value and returns: * Some(t) if predicate returns true (where t is the wrapped value), and * None if predicate returns false.
public flatten(): Option
Converts from Option<Option> to Option
public getIterator(): \Generator
public isNone(): bool
Returns true if the option is none
public isSome(): bool
Returns true if the option contains a value
public map(\callable $f): Option
Maps to another option by applying a function to the contained value
public mapOr(\callable $f, U $value): U
Applies a function to the contained value (if any), or returns the provided default (if not).
public mapOrElse(\callable $f, \callable $default): U
Applies a function to the contained value (if any), or compute a default (if not).
public okOr(E $error): Result<T,E>
Transforms the Option into a Result<T,E>, mapping Some(v) to Ok(v) and None to Err(err).
public okOrElse(\callable $error): Result<T,E>
Transforms the Option into a Result<T,E>, mapping Some(v) to Ok(v) and None to Err(error()).
public or(Option $b): Option
Returns the option if it contains a value, otherwise returns option b.
public orElse(\callable $f): Option
Returns the option if it contains a value, otherwise calls f and returns the result.
public transpose(): Result<Option,E>
Transposes an Option of a Result into a Result of an Option.
public unwrap(): T
Returns the contained value or throws a NoneError if empty
public unwrapNone(): void
Throws a NoneError if empty
public unwrapOr(T $value): T
Returns the contained value or the given value
public unwrapOrElse(\callable $f): T
Returns the contained value or compute it from the given closure
public xor(Option $b): Option
Returns Some if exactly one of this and option b is Some, otherwise returns None.
public zip(Option $b): Option
Zips self with another Option. If self is Some(s) and other is Some(o), this method returns Some([s, o])). Otherwise, None is returned
public zipWith(Option $b, \callable $f): Option
Zips self with another Option with function f If self is Some(s) and other is Some(o), this method returns Some(f(s, o))). Otherwise, None is returned

This class implements \Traversable