mbretter / stk-immutable
Stk Immutable Data objects
2.1.0
2023-07-07 05:32 UTC
Requires
- php: ^8.0
- ext-json: *
Requires (Dev)
- friendsofphp/php-cs-fixer: ^v3.21.1
- phpstan/phpstan: ^1.10.25
- phpunit/phpunit: ^9
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
This library implements the immutable design pattern for objects holding some kind of data.
Maps
Maps can hold objects (stdClass) and/or arrays, they can be nested, very useful when reading/writing from/to noSQL databases like MongoDB.
use Stk\Immutable\Map; $a = new Map((object)['x' => 'foo', 'y' => 'bar']); $b = $a->set('x', 'whatever');
Calling the set method on the object $a does not modify it, a clone with the modifications is returned instead, the original Map will never be modified.
Comparing two Maps is easy, there is no need for writing complicated and resource consuming comparision functions, simply use the identical operator:
if ($a === $b) { ... }