PHP Class Qaribou\Collection\ImmArray

Inheritance: implements Iterato\Iterator, implements ArrayAcces\ArrayAccess, implements Countabl\Countable, implements JsonSerializabl\JsonSerializable
Afficher le fichier Open project: jkoudys/immutable.php Class Usage Examples

Méthodes publiques

Méthode Description
concat ( ) : ImmArray Concat to the end of this array
count ( ) Countable
current ( ) Iterator
filter ( callable $cb ) : ImmArray Filter out elements
fromArray ( array $arr ) : ImmArray Build from an array
fromItems ( Traversable $arr ) : ImmArray Factory for building ImmArrays from any traversable
join ( string $token = ',', string $secondToken = null ) : string Join a set of strings together.
jsonSerialize ( ) JsonSerializable
key ( )
map ( callable $cb ) : ImmArray Map elements to a new ImmArray via a callback
next ( )
offsetExists ( $offset ) ArrayAccess
offsetGet ( $offset )
offsetSet ( $offset, $value )
offsetUnset ( $offset )
reduce ( callable $cb, mixed $initial = null ) Reduce to a single value
rewind ( )
slice ( integer $begin, integer $end = null ) : ImmArray Take a slice of the array
sort ( callable $cb = null ) : ImmArray Return a new sorted ImmArray
sortHeap ( SplHeap $heap ) : ImmArray Sort a new ImmArray by filtering through a heap.
toArray ( )
valid ( )
walk ( callable $cb ) : ImmArray forEach, or "walk" the data Exists primarily to provide a consistent interface, though it's seldom any better than a simple php foreach. Mainly useful for chaining.

Méthodes protégées

Méthode Description
arraySort ( callable $cb = null ) : ImmArray Fallback behaviour to use the builtin array sort functions
heapSort ( callable $cb ) : ImmArray Sort by applying a CallbackHeap and building a new heap Can be efficient for sorting large stored objects.
mergeSort ( callable $cb ) : ImmArray Perform a bottom-up, non-recursive, in-place mergesort.
quickSort ( callable $cb ) : ImmArray A classic quickSort - great for inplace sorting a big fixed array

Private Methods

Méthode Description
__construct ( Traversable $immute ) Create an immutable array

Method Details

arraySort() protected méthode

Fallback behaviour to use the builtin array sort functions
protected arraySort ( callable $cb = null ) : ImmArray
$cb callable The callback for comparison
Résultat ImmArray

concat() public méthode

Concat to the end of this array
public concat ( ) : ImmArray
Résultat ImmArray

count() public méthode

Countable
public count ( )

current() public méthode

Iterator
public current ( )

filter() public méthode

Filter out elements
public filter ( callable $cb ) : ImmArray
$cb callable Function to filter out on false
Résultat ImmArray

fromArray() public static méthode

Build from an array
public static fromArray ( array $arr ) : ImmArray
$arr array
Résultat ImmArray

fromItems() public static méthode

Factory for building ImmArrays from any traversable
public static fromItems ( Traversable $arr ) : ImmArray
$arr Traversable
Résultat ImmArray

heapSort() protected méthode

Sort by applying a CallbackHeap and building a new heap Can be efficient for sorting large stored objects.
protected heapSort ( callable $cb ) : ImmArray
$cb callable The comparison callback
Résultat ImmArray

join() public méthode

Join a set of strings together.
public join ( string $token = ',', string $secondToken = null ) : string
$token string Main token to put between elements
$secondToken string If set, $token on left $secondToken on right
Résultat string

jsonSerialize() public méthode

JsonSerializable
public jsonSerialize ( )

key() public méthode

public key ( )

map() public méthode

Map elements to a new ImmArray via a callback
public map ( callable $cb ) : ImmArray
$cb callable Function to map new data
Résultat ImmArray

mergeSort() protected méthode

Efficient for very-large objects, and written without recursion since PHP isn't well optimized for large recursion stacks.
protected mergeSort ( callable $cb ) : ImmArray
$cb callable The callback for comparison
Résultat ImmArray

next() public méthode

public next ( )

offsetExists() public méthode

ArrayAccess
public offsetExists ( $offset )

offsetGet() public méthode

public offsetGet ( $offset )

offsetSet() public méthode

public offsetSet ( $offset, $value )

offsetUnset() public méthode

public offsetUnset ( $offset )

quickSort() protected méthode

A classic quickSort - great for inplace sorting a big fixed array
protected quickSort ( callable $cb ) : ImmArray
$cb callable The callback for comparison
Résultat ImmArray

reduce() public méthode

Reduce to a single value
public reduce ( callable $cb, mixed $initial = null )
$cb callable Callback( mixed $previous, mixed $current[, mixed $index, mixed $immArray] ):mixed Callback to run reducing function
$initial mixed Initial value for first argument

rewind() public méthode

public rewind ( )

slice() public méthode

Take a slice of the array
public slice ( integer $begin, integer $end = null ) : ImmArray
$begin integer Start index of slice
$end integer End index of slice
Résultat ImmArray

sort() public méthode

Return a new sorted ImmArray
public sort ( callable $cb = null ) : ImmArray
$cb callable The sort callback
Résultat ImmArray

sortHeap() public méthode

Tends to run much faster than array or merge sorts, since you're only sorting the pointers, and the sort function is running in a highly optimized space.
public sortHeap ( SplHeap $heap ) : ImmArray
$heap SplHeap The heap to run for sorting
Résultat ImmArray

toArray() public méthode

public toArray ( )

valid() public méthode

public valid ( )

walk() public méthode

Named walk for historic reasons - forEach is reserved in PHP
public walk ( callable $cb ) : ImmArray
$cb callable Function to call on each element
Résultat ImmArray