PHP 클래스 phpstreams\Stream

저자: Bert Peters ([email protected])
상속: implements IteratorAggregat\IteratorAggregate, implements Countabl\Countable
파일 보기 프로젝트 열기: bertptrs/phpstreams 1 사용 예제들

보호된 프로퍼티들

프로퍼티 타입 설명
$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