PHP Class Qaribou\Collection\ImmArray

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

Public Methods

Method 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.

Protected Methods

Method 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

Method Description
__construct ( Traversable $immute ) Create an immutable array

Method Details

arraySort() protected method

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

concat() public method

Concat to the end of this array
public concat ( ) : ImmArray
return ImmArray

count() public method

Countable
public count ( )

current() public method

Iterator
public current ( )

filter() public method

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

fromArray() public static method

Build from an array
public static fromArray ( array $arr ) : ImmArray
$arr array
return ImmArray

fromItems() public static method

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

heapSort() protected method

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
return ImmArray

join() public method

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
return string

jsonSerialize() public method

JsonSerializable
public jsonSerialize ( )

key() public method

public key ( )

map() public method

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

mergeSort() protected method

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
return ImmArray

next() public method

public next ( )

offsetExists() public method

ArrayAccess
public offsetExists ( $offset )

offsetGet() public method

public offsetGet ( $offset )

offsetSet() public method

public offsetSet ( $offset, $value )

offsetUnset() public method

public offsetUnset ( $offset )

quickSort() protected method

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

reduce() public method

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 method

public rewind ( )

slice() public method

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
return ImmArray

sort() public method

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

sortHeap() public method

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
return ImmArray

toArray() public method

public toArray ( )

valid() public method

public valid ( )

walk() public method

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