alexeyshockov / colada Goto Github PK
View Code? Open in Web Editor NEWHelpers for arrays and collections in PHP
License: MIT License
Helpers for arrays and collections in PHP
License: MIT License
Removals for immutable collections, like Scala: http://www.scala-lang.org/docu/files/collections-api/collections_7.html.
call_user_func()
instead of callable
.array()
insted of short syntax.Something like getOrElse
from http://www.scala-lang.org/docu/files/collections-api/collections_10.html.
Like Google Guava (http://code.google.com/p/guava-libraries/wiki/StringsExplained).
Mark stable classes/methods/functions with @api
.
If isEqualTo()
defined in inherited class, it will not work in comparison.
list($activeUsers, $inactiveUsers) = $users->partition(function($user, $roles) {
return $user->isActive();
});
For sort collection elements with build-in comparator (and with compareTo()
support for objects).
Additions for immutable collections, like Scala: http://www.scala-lang.org/docu/files/collections-api/collections_7.html.
And move this methods to functions in Colada namespace.
For maps, that contains only scalar keys, native array backend will be really better (by comparing to SplObjectStorage).
Like array_chunk()
.
In use case, where keys are unique, we not need multi map, but simple map.
I think, this may be achieved with something like: Collection::groupBy($keyFinder, $uniqueKeys = false)
.
Optimizations and interface for sorted collections.
Interface:
Thoughts on implementation: collect (as is), sort in build().
Optimizations:
For collections with elements of same type some operations can be optimized (where comparison is used).
isAnyMatchBy(), isAllMatchBy(), isNoneMatchBy().
Will be useful with zip()
, like this:
$keys; // Collection.
$elements; // Collection.
$map = $keys->zip($elements)->toMap();
Create builder in one place, like in IteratorCollection
.
May be useful with get_class()
to produce map with current type.
To exapmle, the following code:
var_dump('GO');
$a = [1,2];
$b = to_collection($a)->mapBy(function($v) {
var_dump('Map by');
return $v+1;
});
var_dump($b->count());
... produces the following output:
string(2) "GO"
string(6) "Map by"
string(6) "Map by"
string(6) "Map by"
int(2)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.