Download the PHP package mf/collections-php without Composer
On this page you can find all versions of the php package mf/collections-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mf/collections-php
More information about mf/collections-php
Files in mf/collections-php
Package collections-php
Short Description Collections for PHP - It's basically a syntax sugar over classic array structure, which allows you to use it as classic array, but adds some cool features.
License MIT
Informations about the package collections-php
MFCollections for PHP
It's basically a syntax sugar over classic array structure, which allows you to use it as classic array, but adds some cool features.
Table of Contents
- Installation
- Requirements
- Base Interfaces
- IEnumerable
- ICollection
- IList
- IMap
- ISeq
- ITuple
- Mutable
- Immutable
- Generic
- Arrow Functions
- Plans for next versions
Installation
Requirements
PHP ^8.2
Base Interfaces
Check out Documentation for more details.
IEnumerable
- basic Interface for enumerable
- extends
IteratorAggregate
,Countable
- see Immutable tuple
- see Mutable PrioritizedCollection
ICollection
- basic Interface for Collections
- extends
IEnumerable
- see Mutable collections
- see Immutable collections
IList
A list is an ordered (possibly immutable) series of elements of the same type.
- extends
ICollection
- see Mutable list
- see Immutable list
IMap
A map is an ordered (possibly immutable) series of key values pairs.
- extends
ICollection, ArrayAccess
- see Mutable map
- see Immutable map
ISeq
A sequence is a logical series of elements all of one type.
- extends
ICollection
- see Immutable seq
ITuple
A tuple is a grouping of unnamed but ordered values, possibly of different types.
- extends
IEnumerable
,ArrayAccess
,Stringable
- see Immutable tuple
Mutable Collections
Interfaces
Mutable\Generic\ICollection
,Mutable\Generic\IList
,Mutable\Generic\IMap
Mutable\Generic\ListCollection
- implements
Mutable\Generic\IList
- is
eager
as possible
Mutable\Generic\Map
- implements
Mutable\Generic\IMap
- is
eager
as possible
Mutable\Generic\PrioritizedCollection
- implements
IEnumerable
- holds items with
generic
type bypriority
- is
eager
as possible
Example of strategies by priority
For case when you want to apply only the first strategy
which can do what you want.
You can add strategies dynamically
and still apply them by priority
later.
Immutable Collections
-
internal state
of Immutable\Collection instance willnever change
from the outside (it isreadonly
) $list
is still an emptyImmutable\ListCollection
$listWith1
is new instance ofImmutable\ListCollection
with value1
Interfaces
Immutable\Generic\ICollection
,Immutable\Generic\IList
,Immutable\Generic\IMap
,Immutable\Generic\ISeq
,Immutable\ITuple
Immutable\Generic\ListCollection
- implements
Immutable\Generic\IList
- is
eager
as possible
Immutable\Generic\Map
- implements
Immutable\Generic\IMap
- is
eager
as possible
Immutable\Seq
- implements
Immutable\Generic\ISeq
- is
lazy
as possible (even could beInfinite
)
Immutable\Generic\KVPair
- always has a
Key
and theValue
- key is restricted to
int|string
so it may be used in theforeach
as a key - can contain any values
Immutable\Tuple
- implements
Immutable\ITuple
- must have at least 2 values (otherwise it is just a single value)
- is
eager
as possible - allows
destructuring
,matching
andparsing
/formatting
- can contain any scalar values and/or arrays
- in string representation of a
Tuple
, array values must be separated by;
(not by,
)
- in string representation of a
Parsing
Matching and comparing
Parsing and matching
Formatting
Destructuring
Unpacking
Merging
- merging
Tuples
will automatically flat them (see last example below)
Merging and matching
Sequences and lazy mapping
- if your
Sequence
get mapped and filtered many times (for readability), it is not a problemmap -> map -> filter -> map -> filter -> map
will iterate the collection only once (for applying all modifiers at once)- this modification is done when another method is triggered, so adding new modifier is an atomic operation
- all the values are generated on the fly, so it may end on out of memory exception
Plans for next versions
- use
Symfony/Stopwatch
in unit tests - even better documentation (current)