Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# xphp-lang/collection
# xphp-lang/collections

Generic, immutable, variance-aware collections for PHP, built on
[xphp](https://github.com/xphp-lang/xphp) monomorphization — real generics with declaration-site
Expand Down Expand Up @@ -28,7 +28,7 @@ Immutable concrete classes (`readonly`):
| `Pair<K, out V>` | `Entry<K, V>` |
| `Couple<out A, out B>` | `Tuple<A, B>` (`readonly`; `component1()`/`component2()` destructuring) |

Types are grouped by concept under `XPHP\Collection`: the root `Collection`/`Comparator`, then `Lists\`
Types are grouped by concept under `XPHP\Collections`: the root `Collection`/`Comparator`, then `Lists\`
(including the static `ImmutableGrouping`/`ImmutableZipping`/`ImmutableReducing` helpers), `Sets\`, `Maps\`
(which holds `Map`/`Entry`/`ImmutableMap`/`Pair`), and `Tuples\` (`Tuple`/`Couple`), plus `Support\` for the
internal base. The layout is frozen and additive-only —
Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "xphp-lang/collection",
"name": "xphp-lang/collections",
"description": "Generic, immutable, variance-aware collections for PHP, powered by xphp monomorphization (real generics with declaration-site variance).",
"license": "MIT",
"type": "library",
Expand Down Expand Up @@ -27,13 +27,13 @@
"autoload": {
"psr-4": {
"XPHP\\Generated\\": "cache/Generated/",
"XPHP\\Collection\\": ["src/", "build/"]
"XPHP\\Collections\\": ["src/", "build/"]
}
},
"autoload-dev": {
"psr-4": {
"XPHP\\Collection\\Tests\\": "build/",
"XPHP\\Collection\\Example\\": "build/"
"XPHP\\Collections\\Tests\\": "build/",
"XPHP\\Collections\\Example\\": "build/"
}
},
"scripts": {
Expand Down
12 changes: 6 additions & 6 deletions docs/adr/0006-namespace-layout.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ survives xphp monomorphization — `class_alias()` is a runtime hack that does n
template/variance machinery. So **relocating a type after release is a hard breaking change with no
soft-migration path**. The layout must be decided before a stable release and then frozen.

A flat namespace (everything under `XPHP\Collection`) mixes the root abstraction with leaf and helper
A flat namespace (everything under `XPHP\Collections`) mixes the root abstraction with leaf and helper
types (`Entry`/`Pair` sat beside `Collection`) and does not scale as the mutable tier and other data
structures arrive.

Expand All @@ -20,11 +20,11 @@ Group types by data-structure **concept**, one namespace per family, carrying th

| Namespace | Types |
|---|---|
| `XPHP\Collection` | `Collection` (root supertype), `Comparator` (root utility) |
| `XPHP\Collection\Lists` | `OrderedCollection`, `ImmutableList`, `ImmutableGrouping`, `ImmutableZipping` (later `MutableList`) |
| `XPHP\Collection\Sets` | `Set`, `ImmutableSet` (later `MutableSet`) |
| `XPHP\Collection\Maps` | `Map`, `Entry`, `ImmutableMap`, `Pair` (later `MutableMap`) |
| `XPHP\Collection\Support` | `AbstractImmutableCollection` (internal base) |
| `XPHP\Collections` | `Collection` (root supertype), `Comparator` (root utility) |
| `XPHP\Collections\Lists` | `OrderedCollection`, `ImmutableList`, `ImmutableGrouping`, `ImmutableZipping` (later `MutableList`) |
| `XPHP\Collections\Sets` | `Set`, `ImmutableSet` (later `MutableSet`) |
| `XPHP\Collections\Maps` | `Map`, `Entry`, `ImmutableMap`, `Pair` (later `MutableMap`) |
| `XPHP\Collections\Support` | `AbstractImmutableCollection` (internal base) |

Family folders are **plural** (`Lists`/`Sets`/`Maps`) to dodge the reserved word `List`, which is
illegal as a namespace segment (the same reason the ordered type is not named `List`). `Sequence` is
Expand Down
2 changes: 1 addition & 1 deletion docs/adr/0008-list-to-map-derivations.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ runtime values are perfectly ordinary maps of lists; only the *static specializa
## Decision

Host both derivations as **static generic methods on a plain, non-variant helper class**,
`XPHP\Collection\Lists\ImmutableGrouping`:
`XPHP\Collections\Lists\ImmutableGrouping`:

```php
ImmutableGrouping::groupBy<E, L>(OrderedCollection<E> $list, callable $keyOf): ImmutableMap<L, ImmutableList<E>>
Expand Down
2 changes: 1 addition & 1 deletion examples/Book.xphp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace XPHP\Collection\Example;
namespace XPHP\Collections\Example;

final class Book extends Product
{
Expand Down
4 changes: 2 additions & 2 deletions examples/ByName.xphp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

declare(strict_types=1);

namespace XPHP\Collection\Example;
namespace XPHP\Collections\Example;

use XPHP\Collection\Comparator;
use XPHP\Collections\Comparator;

/**
* A comparator over the supertype Product (so it can also order Books, by contravariance).
Expand Down
18 changes: 9 additions & 9 deletions examples/Demo.xphp
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

declare(strict_types=1);

namespace XPHP\Collection\Example;

use XPHP\Collection\Lists\ImmutableGrouping;
use XPHP\Collection\Lists\ImmutableList;
use XPHP\Collection\Lists\ImmutableReducing;
use XPHP\Collection\Lists\ImmutableZipping;
use XPHP\Collection\Lists\OrderedCollection;
use XPHP\Collection\Maps\ImmutableMap;
use XPHP\Collection\Sets\ImmutableSet;
namespace XPHP\Collections\Example;

use XPHP\Collections\Lists\ImmutableGrouping;
use XPHP\Collections\Lists\ImmutableList;
use XPHP\Collections\Lists\ImmutableReducing;
use XPHP\Collections\Lists\ImmutableZipping;
use XPHP\Collections\Lists\OrderedCollection;
use XPHP\Collections\Maps\ImmutableMap;
use XPHP\Collections\Sets\ImmutableSet;

use function array_map;
use function implode;
Expand Down
2 changes: 1 addition & 1 deletion examples/Product.xphp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace XPHP\Collection\Example;
namespace XPHP\Collections\Example;

class Product
{
Expand Down
2 changes: 1 addition & 1 deletion src/Collection.xphp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace XPHP\Collection;
namespace XPHP\Collections;

use Countable;
use IteratorAggregate;
Expand Down
2 changes: 1 addition & 1 deletion src/Comparator.xphp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace XPHP\Collection;
namespace XPHP\Collections;

/**
* A comparison strategy over values of type `T`.
Expand Down
4 changes: 2 additions & 2 deletions src/Lists/ImmutableGrouping.xphp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

declare(strict_types=1);

namespace XPHP\Collection\Lists;
namespace XPHP\Collections\Lists;

use XPHP\Collection\Maps\ImmutableMap;
use XPHP\Collections\Maps\ImmutableMap;

/**
* List-to-map derivations: grouping and indexing.
Expand Down
10 changes: 5 additions & 5 deletions src/Lists/ImmutableList.xphp
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

declare(strict_types=1);

namespace XPHP\Collection\Lists;
namespace XPHP\Collections\Lists;

use XPHP\Collection\Comparator;
use XPHP\Collection\Support\AbstractImmutableCollection;
use XPHP\Collection\Tuples\Couple;
use XPHP\Collection\Tuples\Tuple;
use XPHP\Collections\Comparator;
use XPHP\Collections\Support\AbstractImmutableCollection;
use XPHP\Collections\Tuples\Couple;
use XPHP\Collections\Tuples\Tuple;

use OutOfRangeException;

Expand Down
2 changes: 1 addition & 1 deletion src/Lists/ImmutableReducing.xphp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace XPHP\Collection\Lists;
namespace XPHP\Collections\Lists;

/**
* Widening reduction: fold a list into an accumulator whose type may be a supertype of the element.
Expand Down
6 changes: 3 additions & 3 deletions src/Lists/ImmutableZipping.xphp
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

declare(strict_types=1);

namespace XPHP\Collection\Lists;
namespace XPHP\Collections\Lists;

use XPHP\Collection\Tuples\Couple;
use XPHP\Collection\Tuples\Tuple;
use XPHP\Collections\Tuples\Couple;
use XPHP\Collections\Tuples\Tuple;

use function count;
use function min;
Expand Down
4 changes: 2 additions & 2 deletions src/Lists/OrderedCollection.xphp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

declare(strict_types=1);

namespace XPHP\Collection\Lists;
namespace XPHP\Collections\Lists;

use XPHP\Collection\Collection;
use XPHP\Collections\Collection;

/**
* A read-only collection with a stable positional order and index access.
Expand Down
2 changes: 1 addition & 1 deletion src/Maps/Entry.xphp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace XPHP\Collection\Maps;
namespace XPHP\Collections\Maps;

/**
* A read-only key/value pair — the element type of a {@see Map}.
Expand Down
6 changes: 3 additions & 3 deletions src/Maps/ImmutableMap.xphp
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

declare(strict_types=1);

namespace XPHP\Collection\Maps;
namespace XPHP\Collections\Maps;

use XPHP\Collection\Lists\ImmutableList;
use XPHP\Collection\Lists\OrderedCollection;
use XPHP\Collections\Lists\ImmutableList;
use XPHP\Collections\Lists\OrderedCollection;

use function array_key_exists;
use function array_keys;
Expand Down
4 changes: 2 additions & 2 deletions src/Maps/Map.xphp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

declare(strict_types=1);

namespace XPHP\Collection\Maps;
namespace XPHP\Collections\Maps;

use XPHP\Collection\Lists\OrderedCollection;
use XPHP\Collections\Lists\OrderedCollection;

/**
* A read-only mapping from keys of type `K` to values of type `V`.
Expand Down
2 changes: 1 addition & 1 deletion src/Maps/Pair.xphp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace XPHP\Collection\Maps;
namespace XPHP\Collections\Maps;

/**
* The immutable concrete {@see Entry}. `readonly` enforces immutability; the key/value
Expand Down
4 changes: 2 additions & 2 deletions src/Sets/ImmutableSet.xphp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

declare(strict_types=1);

namespace XPHP\Collection\Sets;
namespace XPHP\Collections\Sets;

use XPHP\Collection\Support\AbstractImmutableCollection;
use XPHP\Collections\Support\AbstractImmutableCollection;

use function array_filter;
use function array_map;
Expand Down
4 changes: 2 additions & 2 deletions src/Sets/Set.xphp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

declare(strict_types=1);

namespace XPHP\Collection\Sets;
namespace XPHP\Collections\Sets;

use XPHP\Collection\Collection;
use XPHP\Collections\Collection;

/**
* A read-only collection with no duplicate elements. Covariant in `E`.
Expand Down
4 changes: 2 additions & 2 deletions src/Support/AbstractImmutableCollection.xphp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

declare(strict_types=1);

namespace XPHP\Collection\Support;
namespace XPHP\Collections\Support;

use XPHP\Collection\Collection;
use XPHP\Collections\Collection;

use ArrayIterator;
use Traversable;
Expand Down
2 changes: 1 addition & 1 deletion src/Tuples/Couple.xphp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace XPHP\Collection\Tuples;
namespace XPHP\Collections\Tuples;

/**
* The immutable concrete {@see Tuple}. `readonly` enforces immutability; both slots are private so the
Expand Down
6 changes: 3 additions & 3 deletions src/Tuples/Tuple.xphp
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

declare(strict_types=1);

namespace XPHP\Collection\Tuples;
namespace XPHP\Collections\Tuples;

/**
* A fully covariant, positional 2-tuple — an ordered pair of read-only slots.
*
* Distinct from {@see \XPHP\Collection\Maps\Entry} (the map entry, whose key `K` is invariant because a
* Distinct from {@see \XPHP\Collections\Maps\Entry} (the map entry, whose key `K` is invariant because a
* `Map` consumes it in `get(K)`): a tuple is purely positional and read-only, so both slots are output-only
* and the type is covariant in both (`out A`, `out B`) — Kotlin's `Pair<out A, out B>`. Returned by positional
* operations such as {@see \XPHP\Collection\Lists\ImmutableList::partition()}.
* operations such as {@see \XPHP\Collections\Lists\ImmutableList::partition()}.
*/
interface Tuple<out A, out B>
{
Expand Down
8 changes: 4 additions & 4 deletions tests/ComparatorTest.xphp
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

declare(strict_types=1);

namespace XPHP\Collection\Tests;
namespace XPHP\Collections\Tests;

use PHPUnit\Framework\TestCase;
use XPHP\Collection\Comparator;
use XPHP\Collection\Tests\Fixtures\Book;
use XPHP\Collection\Tests\Fixtures\ByName;
use XPHP\Collections\Comparator;
use XPHP\Collections\Tests\Fixtures\Book;
use XPHP\Collections\Tests\Fixtures\ByName;

final class ComparatorTest extends TestCase
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Fixtures/Book.xphp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace XPHP\Collection\Tests\Fixtures;
namespace XPHP\Collections\Tests\Fixtures;

/**
* Test fixture: a subtype of {@see Product}. Used as the single element type across the
Expand Down
4 changes: 2 additions & 2 deletions tests/Fixtures/ByName.xphp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

declare(strict_types=1);

namespace XPHP\Collection\Tests\Fixtures;
namespace XPHP\Collections\Tests\Fixtures;

use XPHP\Collection\Comparator;
use XPHP\Collections\Comparator;

/**
* Test fixture: a {@see Comparator} over the supertype {@see Product}, used to exercise
Expand Down
2 changes: 1 addition & 1 deletion tests/Fixtures/Product.xphp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace XPHP\Collection\Tests\Fixtures;
namespace XPHP\Collections\Tests\Fixtures;

/**
* Test fixture: a supertype used to exercise covariance. Declared in `.xphp` so the
Expand Down
12 changes: 6 additions & 6 deletions tests/Lists/ImmutableGroupingTest.xphp
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

declare(strict_types=1);

namespace XPHP\Collection\Tests\Lists;
namespace XPHP\Collections\Tests\Lists;

use PHPUnit\Framework\TestCase;
use XPHP\Collection\Lists\ImmutableGrouping;
use XPHP\Collection\Lists\ImmutableList;
use XPHP\Collection\Maps\Map;
use XPHP\Collection\Tests\Fixtures\Book;
use XPHP\Collection\Tests\Fixtures\Product;
use XPHP\Collections\Lists\ImmutableGrouping;
use XPHP\Collections\Lists\ImmutableList;
use XPHP\Collections\Maps\Map;
use XPHP\Collections\Tests\Fixtures\Book;
use XPHP\Collections\Tests\Fixtures\Product;

final class ImmutableGroupingTest extends TestCase
{
Expand Down
Loading
Loading