scalikephp

ScalikeTraversableInterface extends ArrayAccess, Countable, IteratorAggregate, JsonSerializable

Scala like Traversable Interface.

Table of Contents

drop()  : static
Selects all elements except first `$n` ones.
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.
filter()  : static
Selects all elements of this collection which satisfy a predicate.
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.
flatMap()  : static
Builds a new collection by applying a function to all elements of this collection and using the elements of the resulting collections.
flatten()  : static
Converts this collection of traversable collections into a collection formed by the elements of these collections.
fold()  : mixed
Folds the elements of this collection using the specified associative binary operator.
forAll()  : bool
Tests whether a predicate holds for all elements of this collection.
generate()  : Generator
Creates a new {@link Generator} from this collection.
groupBy()  : Map|array<string|int, Seq>
Partitions this collection into a map of collections according to some discriminator function.
head()  : mixed
Selects the first element of this collection.
headOption()  : Option
Optionally selects the first element.
isEmpty()  : bool
Tests whether this collection is empty.
last()  : mixed
Selects the last element of this collection.
lastOption()  : Option
Optionally selects the last element.
map()  : static
Builds a new collection by applying a function to all elements of this collection.
max()  : mixed
Finds the largest element.
maxBy()  : mixed
Finds the first element which yields the largest value measured by function `$f`.
min()  : mixed
Finds the smallest element.
minBy()  : mixed
Finds the first element which yields the smallest value measured by function `$f`.
mkString()  : string
Returns all elements of this collection in a string using a separator string.
nonEmpty()  : bool
Tests whether this collection is not empty.
partition()  : array<string|int, mixed>|array<string|int, self>
Splits this collection in two: all elements that satisfy predicate `$p` and all elements that do not.
size()  : int
Returns the size of this collection.
sum()  : float|int
Sums up the elements of this collection.
sumBy()  : float|int
Sums up the elements of this collection.
tail()  : static
Returns rest of this collection without its first element.
take()  : static
Selects the first `$n` elements.
takeRight()  : static
Selects the last `$n` elements.
toArray()  : array<string|int, mixed>
Converts this collection to an array.
toGenerator()  : Generator
Converts this collection to a Generator.
toSeq()  : Seq
Converts this collection to a Seq.

Methods

drop()

Selects all elements except first `$n` ones.

public drop(int $n) : static
Parameters
$n : int

the number of elements to drop from this collection.

Return values
static

a collection consisting of all elements of this collection except the first n ones, or else the empty collection, if this collection has less than n elements. If n is negative, don't drop any elements.

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.

filter()

Selects all elements of this collection which satisfy a predicate.

public filter(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 do not satisfy the given predicate $p.

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.

flatMap()

Builds a new collection by applying a function to all elements of this collection and using the elements of the resulting collections.

public flatMap(Closure $f) : static
Parameters
$f : Closure

the function to apply to each element.

Return values
static

a new collection resulting from concatenating all element collections.

flatten()

Converts this collection of traversable collections into a collection formed by the elements of these collections.

public flatten() : static
Return values
static

a new collection resulting from concatenating all element collections.

fold()

Folds the elements of this collection using the specified associative binary operator.

public fold(mixed $z, Closure $op) : mixed
Parameters
$z : mixed

a neutral element for the fold operation; may be added to the result an arbitrary number of times, and must not change the result (e.g., Nil for list concatenation, 0 for addition, or 1 for multiplication).

$op : Closure

a binary operator that must be associative.

Return values
mixed

the result of applying the fold operator op between all the elements and z, or z if this collection is empty.

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.

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

groupBy()

Partitions this collection into a map of collections according to some discriminator function.

public groupBy(Closure|string $f) : Map|array<string|int, Seq>
Parameters
$f : Closure|string

the discriminator function or key of element.

Return values
Map|array<string|int, Seq>

A map from keys to collections.

head()

Selects the first element of this collection.

public head() : mixed
Tags
throws
LogicException

if this collection is empty.

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.

isEmpty()

Tests whether this collection is empty.

public isEmpty() : bool
Return values
bool

true if this collection contains no elements, false otherwise.

last()

Selects the last element of this collection.

public last() : mixed
Tags
throws
LogicException

if this collection is empty.

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.

map()

Builds a new collection by applying a function to all elements of this collection.

public map(Closure $f) : static
Parameters
$f : Closure

the function to apply to each element.

Return values
static

max()

Finds the largest element.

public max() : mixed
Tags
throws
LogicException

if this collection is empty.

Return values
mixed

the largest element of this collection.

maxBy()

Finds the first element which yields the largest value measured by function `$f`.

public maxBy(Closure $f) : mixed
Parameters
$f : Closure

the measuring function.

Return values
mixed

the first element of this collection with the largest value measured by function $f.

min()

Finds the smallest element.

public min() : mixed
Tags
throws
LogicException

if this collection is empty.

Return values
mixed

the smallest element of this collection.

minBy()

Finds the first element which yields the smallest value measured by function `$f`.

public minBy(Closure $f) : mixed
Parameters
$f : Closure

the measuring function.

Return values
mixed

the first element of this collection with the smallest value measured by function $f.

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.

partition()

Splits this collection in two: all elements that satisfy predicate `$p` and all elements that do not.

public partition(Closure $p) : array<string|int, mixed>|array<string|int, self>
Parameters
$p : Closure
Return values
array<string|int, mixed>|array<string|int, self>

an array of, first, all elements that satisfy predicate p and, second, all elements that do not.

sumBy()

Sums up the elements of this collection.

public sumBy(Closure $f) : float|int
Parameters
$f : Closure

the measuring function.

Return values
float|int

the sum of all elements of this collection.

take()

Selects the first `$n` elements.

public take(int $n) : static
Parameters
$n : int

the number of elements to take from this collection.

Return values
static

a collection consisting only of the first $n elements of this collection, or else the whole collection, if it has less than $n elements. If $n is negative, returns an empty collection.

takeRight()

Selects the last `$n` elements.

public takeRight(int $n) : static
Parameters
$n : int

the number of elements to take from this collection.

Return values
static

a collection consisting only of the last $n elements of this collection, or else the whole collection, if it has less than $n elements. If $n is negative, returns an empty collection.

toArray()

Converts this collection to an array.

public toArray() : array<string|int, mixed>
Return values
array<string|int, mixed>

toGenerator()

Converts this collection to a Generator.

public toGenerator() : Generator
Return values
Generator

Search results