alexeyshockov / colada
Collections framework for PHP
Installs: 2 826
Dependents: 3
Suggesters: 0
Security: 0
Stars: 32
Watchers: 7
Forks: 6
Open Issues: 0
Requires
- php: ~7.1
- symfony/polyfill-php72: @stable
- symfony/polyfill-php73: @stable
Requires (Dev)
- danielstjules/stringy: ~2.1 || ~3.0
- giorgiosironi/eris: ^0.11.0
- guzzlehttp/guzzle: ~6.3 || ~7.0@dev
- lstrojny/functional-php: ~1.4
- nesbot/carbon: ~2.0
- nikic/iter: ~1.6 || ~2.0
- php-ds/php-ds: ~1.0
- phpoption/phpoption: ~1.5
- phpunit/phpunit: ~7.0
- react/dns: @stable
- react/partial: ~3.0
- react/promise: @stable
- squizlabs/php_codesniffer: ~3.0
- symfony/stopwatch: ~3.0 || ~4.0
Suggests
- alexeyshockov/colada-x: A small helper function to write closures faster (for PHP < 7.4)
- danielstjules/stringy: Convenient string manipulations
- guzzlehttp/guzzle: The most popular library for HTTP interactions
- lstrojny/functional-php: Some functional primitives
- nesbot/carbon: Convenient date and time manipulations
- nikic/iter: Basic helper functions to work with collections (generators)
- php-ds/php-ds: Effective data structures for PHP (\Colada\iter\ds)
- phpoption/phpoption: Optional values for PHP (\Colada\iter\opt)
- react/partial: Partial functions
- symfony/stopwatch: Timing related stuff (\Colada\iter\sw)
This package is auto-updated.
Last update: 2024-01-12 14:39:17 UTC
README
Goal
Convenient and safe way to work with collections.
...And it's been (more or less) solved by some other libraries, like nikic/iter, doctrine/collections or even php-ds/php-ds. That's why the current version of the library contains just a few helpers for that libraries, to conveniently integrate them together.
Installation
composer require alexeyshockov/colada:~3.0
Usage
The library's functions are split by namespaces, one namespace = specific function a dependency (in most cases).
\Colada\ds\{group_by}
Helpers from this namespace require php-ds/php-ds to be available.
group_by()
function prodices a two dimension array (\ArrayObject
or \Ds\Map
, depends on the group key type), from
an iterable based on a group function.
TODO
\Colada\GuzzleHttp\{coroutine_invoke, coroutine, time_sleep}
\Colada\React\{coroutine_invoke, coroutine}
Helpers from this namespace require guzzlehttp/promises or react/promise to be available.
This is the same concept applied to two most popular libs with async capabilities. If you are familiar with async/await in C# or node.js or coroutines in Go, this should be simple. Take a look at the script, written in callback-style and in coroutine-style:
TODO
TODO
\Colada\iter\opt\{get, head, last, find_one}
Helpers from this namespace require phpoption/phpoption to be available.
\Colada\iter\{to_kv_pairs, each_n_and_last, uasort, uksort}
Simple helpers for general iterable
types.
uasort()
and uksort()
are basically equivalents for the internal ones, but work for arbitrary iterable
type.
Contributing
Running Tests
To run all the tests, install the vendors (with Composer) and execute:
vendor/bin/phpunit --testdox
Public API
All classes or functions that are intended to be used by a user should be marked with @api
PHPDoc tag. Anything without this mark
are internal and should not be used by the end user (no guarantees that the interface will stay the same between
versions).