Releases: DusanKasan/Knapsack
Filter without an argument
- Filter without an argument (defaults to null) will remove falsy values
Intersect added, getNth removed, difference renamed to diff.
- Intersect function added
- Average utility function added
- Concatenate utility function added
- Reduce/reduceRight/second now have the returnAsCollection flag
- Breaking change: getNth removed (to solve ambiguity with takeNth, use values()->get(n))
- Breaking change: difference renamed to diff
Zip and transform added, extract replacing pluck
- Zip function added // zips together items from multiple collections
- Extract function added // extracts data from sub-collections using dot separated key path
- Transform function added // transforms a collection using callable
- Breaking change: combine now stops when it runs out of keys or values
- Breaking change: pluck removed (replaced by extract)
More collection functions, CollectionTrait and bugfixes
There are some new functions, specifically:
- second() // seems useless but really usefull :)
- combine($values) // uses current collection as keys, $values as values
- except($keys) // rejects every item with key found in $keys
- only($keys) // filters only items with key found in $keys
- difference(...$collections) // filters items that are in the original collection but not in any of $collections
- flip() // flips keys with values
- has($key) // checks for the existence of item with $key key
CollectionTrait has been introduced and its usage documented in readme.
A handful of bugfixes also:
- Collection constructor might have experienced conflicts between callable (in array form) and array arguments
- Pluck might have failed on heterogenous collections. Now ignores non-collection items.
Further normalization of return values
Automatic conversion of return values to Collections is no longer happening if you do not explicitly require it. Details in documentation.
New namespace, realize() and more variadics
Project moved to new global namespace DusanKasan (whole namespace is DusanKasan\Knapsack) to avoid conflicts. Collection::realize was introduced to force materialization of the collection (turning lazy collection into non-lazy). Collection::concat and Collection::interleave are now variadic.
Breaking change: toArray and Collection::toArray now behave more logicaly and do not convert items recursively.
Documentation/Readme reflects all these changes.
Version 1.0.0
The project is ready for production use. No known bugs exist.
Total overhaul and move to more functional design
Collection class now uses Generator functions under the hood. The functions are also accessible allowing for functional programming. Performance improved 2x.