PHP code example of stratadox / immutable-collection
1. Go to this page and download the library: Download stratadox/immutable-collection library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
stratadox / immutable-collection example snippets
class Numbers extends ImmutableCollection
{
public function __construct(int ...$items)
{
parent::__construct(...$items);
}
}
class Things extends ImmutableCollection
{
public function __construct(Thing ...$things)
{
parent::__construct(...$things);
}
}
class Numbers extends ImmutableCollection implements Appendable
{
use Appending;
public function __construct(int ...$items)
{
parent::__construct(...$items);
}
}
$numbers = new Numbers(1, 2, 3);
$numbers = $numbers->add(4);
assert($numbers == new Numbers(1, 2, 3, 4));
class Numbers extends ImmutableCollection implements Mergeable, Purgeable
{
use Merging, Purging;
public function __construct(int ...$items)
{
parent::__construct(...$items);
}
}
$numbers = new Numbers(1, 2, 3);
$numbers = $numbers->merge(new Numbers(4, 5, 6));
$numbers = $numbers->remove(3);
assert($numbers == new Numbers(1, 2, 4, 5, 6));
$numbers = (new Numbers(1, 2, 3))
->merge(new Numbers(4, 5, 6))
->remove(3);
assert($numbers == new Numbers(1, 2, 4, 5, 6));
class Things extends ImmutableCollection
{
public function __construct(Thing ...$things)
{
parent::__construct(...$things);
}
public function current(): Thing
{
return parent::current();
}
public function offsetGet($index): Thing
{
return parent::offsetGet($index);
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.