Download the PHP package voltra/lazy-collection without Composer
On this page you can find all versions of the php package voltra/lazy-collection. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download voltra/lazy-collection
More information about voltra/lazy-collection
Files in voltra/lazy-collection
Package lazy-collection
Short Description A library for manipulating collections the lazy way
License MIT
Informations about the package lazy-collection
Lazy Collection
A library for manipulating collections the lazy way
For more info, consult the official documentation or join my official discord server for help with libraries.
Using the library
use LazyCollection\Stream;
There are two ways you can use this library :
- using the factory functions (in the
LazyCollection
namespace) - using the factory static methods
Functions
There are a few functions predefined for you :
collect(...$args)
which creates a stream from the series of argumentsstream($iterable)
which creates a stream wrapping the giveniterable
infiniteRange($start, $step)
which creates an infinite stream of numbers starting from$start
incremented by$step
range($start = 0, $end = null, $step = 1)
which creates an kind of numbers rangesplitBy($str, $separator, $removeEmptyStrings = true)
which creates a stream of strings by splitting$str
into parts using$separator
splitByRegex($str, $re, $removeEmptyStrings = true)
which creates a stream of strings by splitting$str
into parts using the regular expression$re
(cf. [preg_split](Make a stream by splitting a string in parts using a regular expression))
Factories
Stream::fromIterable($iterable)
Stream::range($start = 0, $end = null, $step = 1)
Stream::splitBy($str, $separator, $removeEmptyStrings = true
splitByRegex($str, $re, $removeEmptyStrings = true)
Extend the library
Stream
provides utilities to add methods and factories :
Stream::registerMethod($name, $method)
which can return an instance ofStream
or something elseStream::registerFactory($name, $factory)
which should return an instance ofStream
Why use this library
Its goal is to provide a standalone library for collection manipulation with an elegant and fluent syntax and performance.
Because of its design, the following pieces are strictly equivalent in terms of complexity :
No matter how much operations you use, it will always be O(n)
. The equivalent of a single for-loop.
Note that some operations like reverse
or the likes of unique
and sort
are considered eager operations (or stateful) as they need to iterate over the entire stream once before emitting values themselves.
The point is, any operation you do cost, in the worst case scenario, as much as what you could write by hand.
Badges
All versions of lazy-collection with dependencies
php Version >=7.1.11