PHP Класс phpstreams\Stream

Автор: Bert Peters ([email protected])
Наследование: implements IteratorAggregat\IteratorAggregate, implements Countabl\Countable
Показать файл Открыть проект Примеры использования класса

Защищенные свойства (Protected)

Свойство Тип Описание
$source Backing source for this Stream.

Открытые методы

Метод Описание
__construct ( Traversabl\Traversable | array $source ) Construct a new stream from a traversable source.
all ( callable $predicate = null ) : boolean Return true if all element matches the predicate.
any ( callable $predicate = null ) : boolean Return true if any element matches the predicate.
collect ( phpstreams\Collector $collector )
count ( ) : integer Count the number of elements in this stream.
distinct ( type $strict = false ) : Stream Enforce distinct values.
filter ( callable $filter ) : Stream Apply a filter to the current stream.
flatMap ( callable $unpacker = null ) : Stream Flatten the underlying stream.
getIterator ( )
isSorted ( ) : boolean Check whether this stream is definitely sorted.
isValidSource ( mixed $source ) : boolean Check whether a source is valid.
limit ( integer $limit ) : Stream Limit the stream to some number of elements.
map ( callable $mapping ) : Stream Map the values in the stream to another stream.
reduce ( mixed $identity, callable $binaryOp ) : mixed Reduce the stream using the given binary operation.
skip ( integer $toSkip ) : Stream Skip the first few elements.
sorted ( callable $sort = null ) : Stream Get a sorted view of the stream.
toArray ( boolean $withKeys = true ) : array Convert this stream to an array.

Описание методов

__construct() публичный Метод

Construct a new stream from a traversable source.
public __construct ( Traversabl\Traversable | array $source )
$source Traversabl\Traversable | array The source to create the stream from.

all() публичный Метод

This method short-circuits, so if any item does not match the predicate, no further elements are considered.
public all ( callable $predicate = null ) : boolean
$predicate callable
Результат boolean

any() публичный Метод

This method short-circuits, so if any item matches the predicate, no further items are evaluated.
public any ( callable $predicate = null ) : boolean
$predicate callable
Результат boolean

collect() публичный Метод

public collect ( phpstreams\Collector $collector )
$collector phpstreams\Collector

count() публичный Метод

This method may consume the stream, if it is not repeatable. Use it only when appropriate. As this is simply an implementation of the Countable interface, the count function may be used instead. However, this still may consume the stream.
public count ( ) : integer
Результат integer The number of elements in this Stream.

distinct() публичный Метод

This stream will yield every distinct value only once. Note that internally, it uses in_array for lookups. This is problematic for large numbers of distinct elements, as the complexity of this stream filter becomes O(n * m) with n the number of elements and m the number of distinct values. This mapping preserves key => value relationships, and will yield the values with the first keys encountered.
public distinct ( type $strict = false ) : Stream
$strict type whether to use strict comparisons for uniqueness.
Результат Stream

filter() публичный Метод

Note that filter, like most stream operations, preserves the key => value relationship throughout its execution. That means that there will be missing keys, if you started with a regular array.
public filter ( callable $filter ) : Stream
$filter callable
Результат Stream a new stream yielding only the elements for which the callback returns true.

flatMap() публичный Метод

This method takes each element and unpacks it into a sequence of elements. All individual sequences are concatenated in the resulting stream.
public flatMap ( callable $unpacker = null ) : Stream
$unpacker callable [optional] An unpacker function that can unpack elements into something iterable. Default is to use the identity function.
Результат Stream

getIterator() публичный Метод

public getIterator ( )

isSorted() публичный Метод

This is used to optimize some stream operations, such as distinct(), which only needs constant memory when operating on a sorted list. Any stream operations that potentially change the sorting order should override this method to properly reflect the actual sorting order.
public isSorted ( ) : boolean
Результат boolean

isValidSource() публичный статический Метод

Valid sources are either an array or a Traversable.
public static isValidSource ( mixed $source ) : boolean
$source mixed
Результат boolean True if it is.

limit() публичный Метод

All elements after the limit are not considered or generated, so this can be used with infinite streams.
public limit ( integer $limit ) : Stream
$limit integer The maximum number of elements to return.
Результат Stream

map() публичный Метод

Map the values in the stream to another stream.
public map ( callable $mapping ) : Stream
$mapping callable
Результат Stream a new stream with the variables mapped.

reduce() публичный Метод

The given is applied to every item in the stream in no particular order. The result is then returned. In order for the callable to be a proper reductor, it should be:
  • Commutative, so op($a, $b) is equal to op($b, $a), and
  • Should preserve respect the given identity, i.e. op($a, $identity) = $identity.
If any of these properties do not hold, the output of this function is not defined.
public reduce ( mixed $identity, callable $binaryOp ) : mixed
$identity mixed The identity element.
$binaryOp callable A reduction function, respecting the properties above.
Результат mixed

skip() публичный Метод

This method discards the first few elements from the stream, maintaining key => value relations.
public skip ( integer $toSkip ) : Stream
$toSkip integer
Результат Stream

sorted() публичный Метод

This method yields its values sorted. Sort is done using the default asort() function, or uasort if a sorting function was given. Note that by the nature of sorting things, the entire previous source will be read into memory in order to sort it. This may be a performance issue.
public sorted ( callable $sort = null ) : Stream
$sort callable [optional] a callback to use for sorting.
Результат Stream

toArray() публичный Метод

Convert this stream to an array.
public toArray ( boolean $withKeys = true ) : array
$withKeys boolean [optional] if false, return a simple array containing all values in order. If true (the default) preserve keys.
Результат array An (associative) array of the contents of the stream.

Описание свойств

$source защищенное свойство

Backing source for this Stream.
protected $source