rocketfellows / tuple
Installs: 1 030
Dependents: 3
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
Requires (Dev)
- phpstan/phpstan: ^0.12.90
- phpunit/phpunit: ^8.5
- squizlabs/php_codesniffer: 3.6.2
This package is not auto-updated.
Last update: 2024-11-19 19:55:20 UTC
README
This component is simple implementation of immutable ordered sequence of elements with strict types. Which means that once tuple created it can't be immuted. Tuple also provide elements of the same type.
Installation
composer require rocketfellows/tuple
Usage example
Typed item class:
class TupleItem { private $id; public function __construct(int $id) { $this->id = $id; } public function getId(): int { return $this->id; } }
Items tuple implementation:
use rocketfellows\tuple\Tuple; class Items extends Tuple { public function __construct(TupleItem ...$items) { parent::__construct(...$items); } public function current(): ?TupleItem { return parent::current(); } }
Load tuple and loop through:
$firstTupleItem = new TupleItem(1); $secondTupleItem = new TupleItem(2); $thirdTupleItem = new TupleItem(3); $items = new Items($firstTupleItem, $secondTupleItem, $thirdTupleItem); foreach ($items as $item) { print_r($item->getId()); }
Result:
1 2 3
Contributing
Welcome to pull requests. If there is a major changes, first please open an issue for discussion.
Please make sure to update tests as appropriate.