All notable changes to this project will be documented in this file.
The format is based on Keep a Changelog and this project adheres to Semantic Versioning.
Nothing so far
- Prevent segfaults and exceptions due to debugging info
- Replaced PSR-0 autoloading in favor of PSR-4.
- Added upgrade guide for migrating itertools from 2.x to 3.0
- Added support for php 8.
- Added support for Twig 3.
- The argument to
iterable()
is no longer required, instead, an empty iterator is made when no arguments are given. - The first argument of
->reduce()
is now a required closure.
- Removed support for php 5.
- Removed support for Twig 1.
- Removed everything marked deprecated in the previous major release.
- Removed the option to enable or disable the legacy Twig filters and functions.
- Support for changing the name in Twig
- Enable or disable the legacy Twig filters and functions
When the zicht/framework-extra-bundle
is used to load the Twig extension,
the following allows you to configure these properties.
zicht_framework_extra:
itertools:
twig_name: it # use `it` (default)
twig_enable_legacy_api: true # enable legacy api (default)
-
Marked many functions as deprecated, i.e.
filters\match
is now available asFilters::match
. This is in preparation of the 3.0 release that will be compatible with php 8, which ships with a globalmatch
statement of its own.// Deprecated // function from filters.php, mappings.php, and reductions.php use function Zicht\Iterable\reductions\join; iterable(['a', 'b', 'c'])->reduce(join(' - ')); // New style use Zicht\Itertools\util\Reductions; iterable(['a', 'b', 'c'])->reduce(Reductions::join(' - '));
-
Marked many twig filters and functions as deprecated, i.e.
[1, 2, 3]|filter
is now available as[1, 2, 3]|it.filter
orit([1, 2, 3]).filter
. This is because twig has been adding filters that use the same names as itertools does.{# Deprecated #} {{ entries|group_by('key') }} {# Everything was replaced by `it` #} {{ entries|it.groupBy('key') }}
- Added
constant
mapping helper.
- Small code improvement on how
before
andafter
convert ISO date strings.
- The
before
andafter
filter helpers will now convert ISO date string when the expected value is aDateTimeInterface
.
- Linter fixes.
- Added
cache
andstring
mapping helper. - Added
before
andafter
filter helpers.
- Added
CollapseIterator
usable from php or twig.
- The
select
mapper now accepts either an array or an object as its first parameter, when an object is given thenselect
will create an array with objects, when an array is given thenselect
will create an array with arrays, as before.
- Update
composer.lock
. - Update code to conform with
zicht/standards-php
3.4.0.
ChainTrait
,MapTrait
, andZipTrait
would indicate that they throw\ReflectionException
, while this never happens. This caused other code to give unnecessary warnings.
- Changed the auto loader to only include the src directory.
- Support for Twig v2.
-
The
values
,toArray
, anditems
traits will now work recursively. This is useful when you have a nested iterator and also iterate over those iterators in a nested way (php does not properly support this).In the below example, the
.values
is used to created a nested array, i.e. both theGroupByIterator
and the nestedGroupedIterator
are replaced by an array, this allows multiple iterations to occur at the same time.{% for grouped in items|group_by('EventId')|sorted('first.EventDateTime').values %} {% set first_item = grouped|first %} ... {% endfor %}
- Added mappers
json_encode
andjson_decode
.
- Reducing using
min
ormax
now supports\DateTime
instances.
- Added missing
$sort
parameter to thegroup_by
twig filter extension.
- Added a new filter helper
filters\match
.
- Calling
values()
onGroupByIterator
will return thevalues()
of every item in the group, instead of theGroupedIterator
instances.
- Added
$discardEmptyContainer
parameter tomappings/select
.
- Added
not
filter tofilters.php
- We should no longer use
not_in(...)
and instead usenot(in(...))
.
- Added
$strategy
parameter tomappings/select
. - Added
$discardNull
parameter tomappings/select
.
- DifferenceTrait, this allows a call like $a->difference($b).
- IntersectionTrait, this allows a call like $a->intersection($b).
- first_key and FirstTrait::firstKey, allowing to get the key of the first element in the iterable.
- last_key and LastTrait::lastKey, allowing to get the key of the last element in the iterable.
- Interface definitions for every trait, allowing for optimizations by not having to convert certain instances when it is known to be of the correct type already.
- InfiniteIterableInterface and InfiniteIterableTrait: these represent all Interfaces and traits that apply to an infinite iterable.
- FiniteIterableInterface and FiniteIterableTrait: these represent all Interfaces and traits that apply to a finite iterable.
- $strategy will use twig strategy when getting values, i.e.
- array keys
- object public property
- object public method
- object public method with 'get' prefixed [NEW]
- object public method with 'is' prefixed [NEW]
- object public method with 'has' prefixed [NEW]
- object public method __get
- otherwise, returns null
- $strategy can always be null, string, or \Closure
- ZipIterator now provided keys(), values(), and items()
-
Propagate key property for filters
-
Remove usage of Foo::class
Foo::class was introduced in php 5.5. We do not need, but it is nice to be, compatible with older php versions.
- Fixes bug in KeyValuePair
- Adds mappings/lower and mappings/upper
- Move get_mapping and get_reduction to the twig extension
- Adds chain reduction
- Adds type mapping
- Adds parent::key() in callback
-
Made reductions\chain behavior stateless
Before reductions\chain is released, I feel this change is needed to ensure that the reduction is stateless.
This also fixes cases where the data list that is being iterated over is only a single element long. This would result in that single element being returned (as per reduce behavior). While we expect a ChainIterator as the reduce result.
- Fixes bug in slice combined with infinite iterator
- Fixes bug in filters in and not_in
- Fixes bug in get_reduction
- Adds the GetterTrait to the GroupByIterator
- Adds {Items|Keys|Values}Trait classes
-
select with flatten enabled now behaves as follows:
The select function will, when flatten is enabled, return an array with all values of the iterable. This can now be done using iterable->values().
Moreover, the select function did not properly handle iterables that had duplicate keys (because of the iterator_to_array implementation). This is fixed properly when using the iterable->values() call.
- Adds $STRICT to filters\in and filters\not_in
- Adds filters\equals
- Fixes GetterTrait: instanceof Trait always returns false
- Adds key and select mapping
- Adds a random mapping used to sort items randomly
- Optimize SortedIterator: we only need to call the value getter once per element in the iterable. Before, the value getter was called multiple times per element
- Use __get method to retrieve value
- Adds function iterable
- Adds in and not_in filters
-
Compatability fix for PHP 5.4
Note: Prior to PHP 5.5, empty() only supports variables; anything else will result in a parse error. In other words, the following will not work: empty(trim($name)). Instead, use trim($name) == false.
- Add length
- Adds reversed filter to twig extension
- Provide filter closures with key and value
- null now results in the identity function, which has the same result.
- Renamed $keyStrategy to $strategy
- Fixes filter argument order.
- Fixes reduce trait arguments
-
Move util classes to functions
The Conversions, Mappings, and Reductions classes were effectively namespaces. These have been removed in favor of using actual namespaces.
- Split all traits into separate files
- Adds chaining trait to UniqueIterator
- GroupbyIterator should be able to chain
- Sorted should allow array access
- Gives ArrayAccess to ChainIterator
- Move mixedToClosure to Conversions class
- Add Mapppings util class and twig functions
- Move conversions to Conversions util class
- rename KeyCallback to MapBy
- bugfix for ReversedIterator
- add twig extension file
- Adds chaining trait
- dev branch for itertool chaining
- move method first
- adds function first
- move the reduction closures to their own Reductions class
- fixes a bug where AccumulateIterator would call current on its inner iterator while this inner iterator was not valid
- fixes bug where UniqueFilter would report an incorrect length
- MapIterator now allows ArrayAccess
- the SortedIterator and GroupbyIterator now call their closure with both value and key
- interperate null as an empty list
- adds traits for countable and __debugInfo
- add SliceIterator
- When mixedToValueGetter gets null it will return a closure that behaves as an identity function
- move ArrayAccess methods to ArrayAccessTrait
- UniqueIterator should forget the items it has seen on rewind
- adds the reduce operator
- adds __debugInfo magic method to all applicable iterators
- adds unique and uniqueBy
- adds any and all
- implemented countable in to the SortedIterator
- adds functionality for keeping keys while iterating
- the closure is no longer required for the filter iterator
- the MapIterator will now keep the keys of the input iterator
- MapIterator now provides both iterator keys and values to the callbacks
- added temp var to support 5.4
- fixes key strategy for sorted and groupby
- fix iterator inception
The primary goal of version 2.0 was a different way of handling keys in a sequence. Version 1.0 handled sequences as Python would, i.e. a sequence of values. However, php iterators have both a value and a key assigned to every item in the sequence, version 2.0 takes this into account.
- adds FilterIterator::toArray()
- adds Countable interface to FilterIterator
- adds toArray to groupby iterator
- implemented array access
- renamed 'keyCallback' to 'mapBy', added 'select()' and internally renamed 'mixedToKeyStrategy' to 'mixedToValueGetter'
- adds a few toArray methods
- implements Countable interface for MapIterator
- adds ArrayAccess to GroupedIterator
- adds support for doctrine PersistentCollection
- adds couting to ChainIterator
- consider any doctrine collection to be iterable
- adds revered
- adds stable sorting (i.e. items with the same sorting value retain their order)
- rename SortIterator to SortedIterator
- groupby now also sorts by default
The 1.0 version was short lived, it had one big flaw that was fixed in 2.0. 1.0 has not been, and should not be, used in production code.