PHPackages                             simondeeley/tuple - 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. simondeeley/tuple

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

simondeeley/tuple
=================

An extendable, reusable PHP tuple objet

v1.1.2(8y ago)110[1 PRs](https://github.com/simondeeley/tuple/pulls)GPL-3.0PHPPHP ~7.1

Since Nov 28Pushed 8y ago1 watchersCompare

[ Source](https://github.com/simondeeley/tuple)[ Packagist](https://packagist.org/packages/simondeeley/tuple)[ Docs](https://github.com/simondeeley)[ RSS](/packages/simondeeley-tuple/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (4)Dependencies (1)Versions (8)Used By (0)

Reusable tuple object for PHP
=============================

[](#reusable-tuple-object-for-php)

[![License](https://camo.githubusercontent.com/89868713ab1ef919e1972f727cd4125b04dd9dc3c39e2a45e97c9680a84e4362/68747470733a2f2f706f7365722e707567782e6f72672f73696d6f6e6465656c65792f7475706c652f6c6963656e7365)](https://packagist.org/packages/simondeeley/tuple) [![Latest Stable Version](https://camo.githubusercontent.com/ccfe7a9d1bddec8218eef31cf17c8c1d78a6fc0babbbe62ab6b302554c4cbd04/68747470733a2f2f706f7365722e707567782e6f72672f73696d6f6e6465656c65792f7475706c652f762f737461626c65)](https://packagist.org/packages/simondeeley/tuple) [![Latest Unstable Version](https://camo.githubusercontent.com/6731746dc3e1bea9dcbc8802d91662899e7aa2a4a23017f60be2a8f4318f0e76/68747470733a2f2f706f7365722e707567782e6f72672f73696d6f6e6465656c65792f7475706c652f762f756e737461626c65)](https://packagist.org/packages/simondeeley/tuple) [![Total Downloads](https://camo.githubusercontent.com/9f58b94fc681d49c4d8d7a0f60cbb0e61ffd56e9c62b796dd775aa46b672b590/68747470733a2f2f706f7365722e707567782e6f72672f73696d6f6e6465656c65792f7475706c652f646f776e6c6f616473)](https://packagist.org/packages/simondeeley/tuple) [![Build Status](https://camo.githubusercontent.com/aefbd040908ddc5025e8666b752ee3be046b449cb7bbc31a819e07b74489429d/68747470733a2f2f7472617669732d63692e6f72672f73696d6f6e6465656c65792f7475706c652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/simondeeley/tuple) [![Scrutinizer Code Quality](https://camo.githubusercontent.com/cf6dde7cf3a93c1e20676169b5d28922593fda9c92edce7a90dc7f3d1105e128/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f73696d6f6e6465656c65792f7475706c652f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/simondeeley/tuple/?branch=master) [![Code Coverage](https://camo.githubusercontent.com/ce9394b3a71bee97aa9b7177e74c90316952c6722472ebdeca51839e8faf4831/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f73696d6f6e6465656c65792f7475706c652f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/simondeeley/tuple/?branch=master)

This package provides a tuple type object for PHP. It is based off [simondeeley\\Type](https://github.com/simondeeley/type) package which provides immutable objects.

> In [mathematics](https://en.wikipedia.org/wiki/Mathematics) a **tuple** is a finite ordered list (sequence) of [elements](https://en.wikipedia.org/wiki/Element_(mathematics)). An ***n*-tuple** is a [sequence](https://en.wikipedia.org/wiki/Sequence) (or ordered list) of *n* elements, where *n* is a non-negative integer.
>
> –*[Wikipedia](https://en.wikipedia.org/wiki/Tuple)*

An example of a tuple could be `[1, 2, 3, 4, 5]`. The order of the items in a tuple is important, so given a set of 'A' being `[1, 2, 3]` and 'B' also being `[1, 2, 3]` then it's true that A equals B. However if we have another set 'C' which is `[3, 2, 1]` then this is not equal to A (or B).

This package was born out of a love creating beautifully crafted 'boilerplate' code which can be reused again and again in any number of both simple and complex objects. Most of the ideas used in this package revolve around the need to create the most basic of PHP objects - one that is immutable and unchanging. Trouble is, PHP has a fair few 'magic methods' which, although great for method overriding, are less great for ensuring an immutable state. This package aims to solve that problem and provide a number of base classes to allow you to build easy-to-use immutable classes of your own.

Requirements
============

[](#requirements)

- PHP &gt;= 7.1.0

Installation
============

[](#installation)

```
composer require simondeeley/tuple

```

Usage
=====

[](#usage)

Create your own tuple object

```
use simondeeley\Tuple;

class MyTuple extends Tuple
{
    //...
}
```

This is the starting point to creating a tuple. By default you can have any number of items in your tuple object (up to the limit of PHP's [PHP\_INT\_MAX](http://php.net/manual/en/reserved.constants.php) value). You can override this and create your own maximum length tuples.

Let's go ahead and create a simple tuple called a pair. Unsurprisingly this has a maximum of two items.

```
use simondeeley\Tuple;

class Pair extends Tuple
{
    const MAX_LENGTH = 2;
}
```

Now we have our new class we can create pair-type objects until out hearts content...

```
$numeric = new Pair(1, 2);
$strings = new Pair('A', 'B');
$mixed = new Pair(1024, 'FooBar');
$objects = new Pair($numeric, $strings);
```

As well as a maximum length value, you can also specify minimum length values. By setting the two values as the same, you effectively impose an exact requirement for the number of arguments a tuple can have. This is very useful for creating tuples that are true to their mathematical form, which brings us on to...

Example Tuples
==============

[](#example-tuples)

This package provides two pre-built tuples out-of-the box, [`Single`](https://github.com/simondeeley/type/blob/master/src/Tuples/Single.php) and [`Pair`](https://github.com/simondeeley/type/blob/master/src/Tuples/Pair.php) these provide functionality for *1*-tuple and *2*-tuple objects, respectively. Using them is very simple

```
use simondeeley\Tuples\Single;
use simondeeley\Tuples\Pair;

$single = new Single('foo'); // Can only ever have one argument
$pair = new Pair(10, 20); // Can only ever have exactly two arguments
```

Testing Equality
================

[](#testing-equality)

The base tuple implements the [`TypeEquality`](https://github.com/simondeeley/type/blob/master/src/Type/TypeEquality.php) interface from the [simondeeley\\Type](https://github.com/simondeeley/type) package. Using this equality check we can compare two tuples. Following on from our Pair example above we can do the following

```
$foo = new Pair(1, 2);
$bar = new Pair(1, 2);
$baz = new Pair(2, 1);

$foo->equals($bar); // Returns true
$foo->equals($baz); // Returns false
```

Explore the source code to see how the comparisons are made or to see how the base tuple class is built.

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

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

Every ~1 days

Total

7

Last Release

3084d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/9180037508701a50d15e6806ea198a315ae0702159c9633376eaccab7e6c19e2?d=identicon)[unwarysheep](/maintainers/unwarysheep)

---

Top Contributors

[![simondeeley](https://avatars.githubusercontent.com/u/493834?v=4)](https://github.com/simondeeley "simondeeley (56 commits)")

---

Tags

immutablephpphp7tuplephpsetextendabletuple

### Embed Badge

![Health badge](/badges/simondeeley-tuple/health.svg)

```
[![Health](https://phpackages.com/badges/simondeeley-tuple/health.svg)](https://phpackages.com/packages/simondeeley-tuple)
```

###  Alternatives

[chdemko/sorted-collections

Sorted Collections for PHP &gt;= 8.2

222.5M3](/packages/chdemko-sorted-collections)[imanghafoori/laravel-anypass

A minimal yet powerful package to help you in development.

21421.6k](/packages/imanghafoori-laravel-anypass)

PHPackages © 2026

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