PHPackages                             compono-kit/lists - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. compono-kit/lists

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

compono-kit/lists
=================

Implementations of compono-kit/lists-interfaces

1.0.0(today)001proprietaryPHPPHP &gt;=8.0

Since Jun 20Pushed todayCompare

[ Source](https://github.com/compono-kit/lists)[ Packagist](https://packagist.org/packages/compono-kit/lists)[ RSS](/packages/compono-kit-lists/feed)WikiDiscussions main Synced today

READMEChangelog (1)Dependencies (4)Versions (2)Used By (1)

ComponoKit / Lists
==================

[](#componokit--lists)

**Strongly typed list objects for PHP 8+**

This package provides a lightweight foundation for building *domain-driven*, *immutable*, and *type-safe* list objects in PHP.

Requirements
------------

[](#requirements)

- PHP 8+
- compono-kit/lists-interfaces

Concepts
--------

[](#concepts)

### TypeList vs. ValueList

[](#typelist-vs-valuelist)

A **ValueList** holds native PHP scalars directly:

```
use ComponoKit\Types\Lists\Immutables\StringValueList;

$tags = new StringValueList('php', 'clean-code', 'ddd');
$tags->get(0); // 'php'
```

A **TypeList** holds objects that implement a `RepresentsType` interface (from `compono-kit/types`):

```
use ComponoKit\Types\Lists\Immutables\StringTypeList;

$tags = new StringTypeList(
    new StringType('php'),
    new StringType('clean-code'),
);
$tags->get(0)->toString(); // 'php'
```

### Immutable vs. Mutable

[](#immutable-vs-mutable)

**Immutable** lists never change — operations return a new list:

```
use ComponoKit\Types\Lists\Immutables\IntegerValueList;

$numbers = new IntegerValueList(1, 2, 3);
$more    = $numbers->append(4, 5);

$numbers->count(); // 3 — unchanged
$more->count();    // 5
```

**Mutable** lists modify in place and return `void`:

```
use ComponoKit\Types\Lists\Mutables\IntegerValueList;

$numbers = new IntegerValueList(1, 2, 3);
$numbers->append(4, 5);

$numbers->count(); // 5
```

Basic Usage
-----------

[](#basic-usage)

### Creating a list

[](#creating-a-list)

All lists accept a variadic list of items in their constructor:

```
$prices  = new FloatValueList(9.99, 14.99, 4.50);
$enabled = new BooleanValueList(true, false, true);
$scores  = new IntegerValueList(42, 17, 99);
```

### Accessing items

[](#accessing-items)

```
$list = new StringValueList('a', 'b', 'c');

$list->count();        // 3
$list->first();        // 'a'
$list->last();         // 'c'
$list->get(1);         // 'b'
$list->exists(5);      // false
```

### Iterating

[](#iterating)

Lists implement `Iterator`, so you can use them in a `foreach` directly:

```
foreach ($list as $index => $value) {
    echo "$index: $value\n";
}
```

Operations
----------

[](#operations)

### Append &amp; Prepend

[](#append--prepend)

```
$list = new StringValueList('b', 'c');

$list->append('d', 'e');   // ['b', 'c', 'd', 'e']
$list->prepend('a');       // ['a', 'b', 'c', 'd', 'e']
```

You can also merge two lists of the same type:

```
$first  = new StringValueList('a', 'b');
$second = new StringValueList('c', 'd');

$merged = $first->appendList($second);  // ['a', 'b', 'c', 'd']
```

### Remove &amp; Replace

[](#remove--replace)

```
$list = new IntegerValueList(10, 20, 30);

$list->remove(1);        // [10, 30]
$list->replace(0, 99);   // [99, 30]
```

### Sort, Reverse &amp; Shuffle

[](#sort-reverse--shuffle)

```
$list     = new IntegerValueList(3, 1, 2);
$reversed = $list->reverse();  // [2, 1, 3]
$shuffled = $list->shuffle();  // random order

// Custom sort via a comparer object:
$sorted = $list->sort(new class implements ComparesValues {
    public function compare(mixed $a, mixed $b): int {
        return $a  $b;
    }
});
// [1, 2, 3]
```

### Unique, Diff &amp; Intersect

[](#unique-diff--intersect)

```
$a = new IntegerValueList(1, 2, 2, 3);
$b = new IntegerValueList(2, 3, 4);

$a->unique();          // [1, 2, 3]
$a->diff($b);          // [1]       — in $a but not in $b
$a->intersect($b);     // [2, 3]    — in both
```

### Slice &amp; Split

[](#slice--split)

```
$list  = new IntegerValueList(1, 2, 3, 4, 5);

$slice = $list->slice(1, 3);   // [2, 3, 4]

// Split into chunks of 2:
foreach ($list->split(2) as $chunk) {
    // $chunk is an IntegerValueList
}
```

### Search

[](#search)

```
$list  = new StringValueList('alpha', 'beta', 'gamma');

$index = $list->findIndex(new class implements MatchesValue {
    public function matches(mixed $value): bool {
        return $value === 'beta';
    }
});
// $index === 1
```

### JSON

[](#json)

```
$list = new StringValueList('foo', 'bar');

$list->toJson();        // '["foo","bar"]'
$list->toJson(true);    // pretty-printed
json_encode($list);     // also works — implements JsonSerializable

$restored = StringValueList::fromJson('["foo","bar"]');
```

Extending with Custom Validation
--------------------------------

[](#extending-with-custom-validation)

Override `isValueValid()` in a concrete subclass to add domain constraints. Invalid items throw the matching `Invalid*Exception`.

```
use ComponoKit\Types\Lists\Immutables\AbstractStringValueList;

class EmailList extends AbstractStringValueList
{
    protected static function isValueValid(string $value): bool
    {
        return filter_var($value, FILTER_VALIDATE_EMAIL) !== false;
    }
}

$emails = new EmailList('a@example.com', 'b@example.com');
$emails = $emails->append('c@example.com');

new EmailList('not-an-email'); // throws InvalidStringValueListException
```

The same pattern works for TypeLists:

```
use ComponoKit\Types\Lists\Immutables\AbstractStringTypeList;

class NonEmptyStringList extends AbstractStringTypeList
{
    protected static function isValueValid(RepresentsString $type): bool
    {
        return $type->toString() !== '';
    }
}
```

Available List Types
--------------------

[](#available-list-types)

TypeTypeListValueListString`StringTypeList``StringValueList`Integer`IntegerTypeList``IntegerValueList`Float`FloatTypeList``FloatValueList`Boolean`BooleanTypeList``BooleanValueList`Mixed`MixedTypeList``MixedValueList`Each type exists in both `Immutables\` and `Mutables\` namespaces.

###  Health Score

37

—

LowBetter than 81% of packages

Maintenance100

Actively maintained with recent releases

Popularity0

Limited adoption so far

Community5

Small or concentrated contributor base

Maturity38

Early-stage or recently created project

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

0d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/8b4875ebadf24ddeae09bd59c44c9a86a61c3d3892fe1d4a264ad167b6d230cc?d=identicon)[Hansel23](/maintainers/Hansel23)

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/compono-kit-lists/health.svg)

```
[![Health](https://phpackages.com/badges/compono-kit-lists/health.svg)](https://phpackages.com/packages/compono-kit-lists)
```

###  Alternatives

[elhebert/laravel-sri

Subresource Integrity hash generator for laravel

39241.9k](/packages/elhebert-laravel-sri)[mtdowling/burgomaster

Packages up PHP packages into zips and phars

2780.9k12](/packages/mtdowling-burgomaster)[francescomalatesta/laravel-circuit-breaker

A circuit breaker pattern implementation for the Laravel framework

2919.2k2](/packages/francescomalatesta-laravel-circuit-breaker)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
