scalikephp

Option extends ScalikeTraversable Uses OptionBuilder

Scala like Option.

Table of Contents

each()  : void
Apply `$f` to each element for its side effects.
exists()  : bool
Tests whether a predicate holds for at least one element of this collection.
filterNot()  : static
Selects all elements of this collection which do not satisfy a predicate.
find()  : Option
Finds the first element of this collection satisfying a predicate, if any.
forAll()  : bool
Tests whether a predicate holds for all elements of this collection.
from()  : Option
Returns an Option of the value.
fromArray()  : Option
Returns an Option of the array element.
generate()  : Generator
Creates a new {@link Generator} from this collection.
get()  : mixed
Returns the value, throw exception if empty.
getOrElse()  : mixed
Returns the value if the Option is non-empty, otherwise return the result of evaluating `$default`.
getOrElseValue()  : mixed
Returns the value if this Option is non-empty, otherwise return the `$default`.
head()  : mixed
Selects the first element of this collection.
headOption()  : Option
Optionally selects the first element.
isDefined()  : bool
Returns true if this Option is non-empty, false otherwise.
last()  : mixed
Selects the last element of this collection.
lastOption()  : Option
Optionally selects the last element.
mkString()  : string
Returns all elements of this collection in a string using a separator string.
none()  : None
Returns the None instance.
nonEmpty()  : bool
Tests whether this collection is not empty.
offsetSet()  : void
PHP magic method: offsetSet.
offsetUnset()  : void
PHP magic method: offsetUnset.
orElse()  : Option
Returns this Option if it is non-empty, otherwise return the result of evaluating `$alternative`.
orNull()  : null|mixed
Returns the value if this Option is non-empty, otherwise return `null`.
pick()  : Option
Returns the value of a single column of this Option's value if it exists, otherwise return None.
some()  : Some
Returns a Some of the value.
sum()  : float|int
Sums up the elements of this collection.
tail()  : static
Returns rest of this collection without its first element.

Methods

each()

Apply `$f` to each element for its side effects.

public each(Closure $f) : void
Parameters
$f : Closure

the function to apply to each element.

Return values
void

exists()

Tests whether a predicate holds for at least one element of this collection.

public exists(Closure $p) : bool
Parameters
$p : Closure

the predicate used to test elements.

Return values
bool

true if the given predicate $p is satisfied by at least one element of this collection, otherwise false.

filterNot()

Selects all elements of this collection which do not satisfy a predicate.

public filterNot(Closure $p) : static
Parameters
$p : Closure

the predicate used to test elements.

Return values
static

a new collection consisting of all elements of this collection that satisfy the given predicate $p.

find()

Finds the first element of this collection satisfying a predicate, if any.

public find(Closure $p) : Option
Parameters
$p : Closure

the predicate used to test elements.

Return values
Option

an Option containing the first element in this collection that satisfies $p, or None if none exists.

forAll()

Tests whether a predicate holds for all elements of this collection.

public forAll(Closure $p) : bool
Parameters
$p : Closure

the predicate used to test elements.

Return values
bool

true if this collection is empty or the given predicate p holds for all elements of this collection, otherwise false.

from()

Returns an Option of the value.

public final static from(mixed $value[, mixed $none = null ]) : Option
Parameters
$value : mixed
$none : mixed = null
Return values
Option

fromArray()

Returns an Option of the array element.

public final static fromArray(array<string|int, mixed>|ArrayAccess $array, int|string $key[, mixed $none = null ]) : Option
Parameters
$array : array<string|int, mixed>|ArrayAccess
$key : int|string
$none : mixed = null
Return values
Option

generate()

Creates a new {@link Generator} from this collection.

public generate(Closure $f) : Generator
Parameters
$f : Closure

the function to apply to each element. it should returns a .

Return values
Generator

get()

Returns the value, throw exception if empty.

public abstract get() : mixed
Tags
throws
LogicException

if this Option is empty.

Return values
mixed

getOrElse()

Returns the value if the Option is non-empty, otherwise return the result of evaluating `$default`.

public abstract getOrElse(Closure $default) : mixed
Parameters
$default : Closure

the default expression.

Return values
mixed

getOrElseValue()

Returns the value if this Option is non-empty, otherwise return the `$default`.

public abstract getOrElseValue(mixed $default) : mixed
Parameters
$default : mixed

the default value.

Return values
mixed

head()

Selects the first element of this collection.

public head() : mixed
Return values
mixed

the first element of this collection.

headOption()

Optionally selects the first element.

public headOption() : Option
Return values
Option

the first element of this collection if it is non-empty, None if it is empty.

isDefined()

Returns true if this Option is non-empty, false otherwise.

public abstract isDefined() : bool
Return values
bool

last()

Selects the last element of this collection.

public last() : mixed
Return values
mixed

the last element of this collection.

lastOption()

Optionally selects the last element.

public lastOption() : Option
Return values
Option

the last element of this collection if it is non-empty, None if it is empty.

mkString()

Returns all elements of this collection in a string using a separator string.

public mkString([string $sep = '' ]) : string
Parameters
$sep : string = ''

the separator string.

Return values
string

a string representation of this collection. In the resulting string the string representations (w.r.t. the method __toString) of all elements of this collection are separated by the string sep.

nonEmpty()

Tests whether this collection is not empty.

public nonEmpty() : bool
Return values
bool

true if this collection does not contain any elements, false otherwise.

offsetSet()

PHP magic method: offsetSet.

public offsetSet(mixed $offset, mixed $value) : void
Parameters
$offset : mixed
$value : mixed
Return values
void

offsetUnset()

PHP magic method: offsetUnset.

public offsetUnset(mixed $offset) : void
Parameters
$offset : mixed
Return values
void

orElse()

Returns this Option if it is non-empty, otherwise return the result of evaluating `$alternative`.

public abstract orElse(Closure $alternative) : Option
Parameters
$alternative : Closure
Return values
Option

orNull()

Returns the value if this Option is non-empty, otherwise return `null`.

public abstract orNull() : null|mixed
Return values
null|mixed

pick()

Returns the value of a single column of this Option's value if it exists, otherwise return None.

public abstract pick(string $name) : Option
Parameters
$name : string

the key of array, or property name.

Return values
Option

some()

Returns a Some of the value.

public final static some(mixed $value) : Some
Parameters
$value : mixed
Return values
Some

sum()

Sums up the elements of this collection.

public sum() : float|int
Return values
float|int

the sum of all elements of this collection.

tail()

Returns rest of this collection without its first element.

public tail() : static
Return values
static

Search results