p810/tuple

There is no license information available for the latest version (2.0.0) of this package.

An implementation of tuples in PHP.

2.0.0 2020-03-19 21:19 UTC

This package is auto-updated.

Last update: 2024-05-20 06:15:45 UTC


README

An implementation of tuples in PHP.

Installation

composer require p810/tuple --no-dev

Usage

<?php

use function p810\Tuple\tuple;

$tuple = tuple('foo', 'bar');

You can also use the Tag Space Unicode character (U+E0020) as a function to make it look like tuples do in Python. This is a proof of concept that I thought would be fun to add. Your coworkers probably won't think it's very fun though so please, weigh your options before using this.

$tuple = 󠀠('hello', 'world');
var_dump($tuple); // => p810\Tuple\Tuple#3 (2) {...}

Why?

This is a project I wanted to take on just because. I borrowed the idea from Python, which was my first introduction to the concept.

All in all, this utility is just a wrapper around a PHP object that implements ArrayAccess and restricts the ability to update, set, or remove items, which makes it immutable.