Download the PHP package xphere/lazzzy without Composer
On this page you can find all versions of the php package xphere/lazzzy. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download xphere/lazzzy
More information about xphere/lazzzy
Files in xphere/lazzzy
Package lazzzy
Short Description Lazy collections for PHP
License MIT
Homepage http://github.com/xPheRe/Lazzzy
Informations about the package lazzzy
Lazzzy
Lazy collection library for PHP.
Wrap your iterables in a thin layer of pure lazyness, so they can be lazy-evaluated while you're being lazy too. :D
Why would I want that?
Collections are everywhere, but you usually don't want to materialize them in each operation. That's where lazyness come in handy. This allows you to map and filter in zero initialization time, for later evaluation when the time is right.
Features
- Convert anything into an iterable: arrays, iterators, functions, generators... you name it. [*]
- Map and filter with multiple functions on initialization, execute once on evaluation
- Handles infinite iterators
[*] planned
Compatibility
Lazzzy requires PHP 5.4 or higher for basic usage.
Installation
Just use composer to add to your project:
Usage
NOTE: Lazzzy is still in alpha, so don't rely on current methods. Just sayin'
Functions
Container::from(x) # lazy
Static function. Converts almost anything into an iterable.
Returns a Container
object wrapping the iterable.
Container::getIterator()
Honors \IteratorAggregate
interface so you can foreach
over Container
s.
Container::toAssoc() # not lazy
Iterates over the container, applying all transformations. Returns the resulting array.
Container::toArray() # not lazy
Like toAssoc
method, but discards keys.
Container::each(fn) # not lazy
Iterates over the container, executing fn
on each iteration.
Returns nothing.
Container::map(fn) # lazy (a -> b) -> [a] -> [b]
Calls fn
transformation on each iteration of [a]
.
Container::filter(fn) # lazy (a -> Bool) -> [a] -> [a]
Filters elements for which fn
function returns truthy values.
Container::take(number) # lazy n -> [a] -> [a]
Takes n
items from the iterator. n
must be an integer greater than zero.
Container::takeWhile(fn) # lazy n -> [a] -> [a]
Takes items while the condition fn
is truthy.
More to come
- Container::skip(n)
- Container::skipUntil(fn)
- Container::fold(fn, x?)
- Container::foldr(fn, x?)
- Container::find(fn)
- Container::every(fn)
- Container::any(fn)
- Container::size()
Contributions
Please contribute with the project on GitHub
Author
Berny Cantos Contact: [email protected] GitHub: xPheRe Twitter: xPheRe
License
Lazzzy is licensed under the MIT License. See LICENSE file for full details.