The Sequence interface

Introduction

A Sequence describes the behaviour of values arranged in a single, linear dimension. Some languages refer to this as a "List". It’s similar to an array that uses incremental integer keys, with the exception of a few characteristics:

  • Values will always be indexed as [0, 1, 2, …, size - 1].
  • Only allowed to access values by index in the range [0, size - 1].

Use cases:

  • Wherever you would use an array as a list (not concerned with keys).
  • A more efficient alternative to SplDoublyLinkedList and SplFixedArray.

Interface synopsis

Ds\Sequence extends Ds\Collection ArrayAccess
/* Methods */
abstract public void Ds\Sequence::allocate(int $capacity)
abstract public void Ds\Sequence::apply(callable $callback)
abstract public int Ds\Sequence::capacity()
abstract public bool Ds\Sequence::contains(mixed ...$values)
abstract public Ds\Sequence Ds\Sequence::filter(callable $callback = ?)
abstract public mixed Ds\Sequence::find(mixed $value)
abstract public mixed Ds\Sequence::first()
abstract public mixed Ds\Sequence::get(int $index)
abstract public void Ds\Sequence::insert(int $index, mixed ...$values)
abstract public string Ds\Sequence::join(string $glue = ?)
abstract public mixed Ds\Sequence::last()
abstract public Ds\Sequence Ds\Sequence::map(callable $callback)
abstract public Ds\Sequence Ds\Sequence::merge(mixed $values)
abstract public mixed Ds\Sequence::pop()
abstract public void Ds\Sequence::push(mixed ...$values)
abstract public mixed Ds\Sequence::reduce(callable $callback, mixed $initial = ?)
abstract public mixed Ds\Sequence::remove(int $index)
abstract public void Ds\Sequence::reverse()
abstract public Ds\Sequence Ds\Sequence::reversed()
abstract public void Ds\Sequence::rotate(int $rotations)
abstract public void Ds\Sequence::set(int $index, mixed $value)
abstract public mixed Ds\Sequence::shift()
abstract public Ds\Sequence Ds\Sequence::slice(int $index, int $length = ?)
abstract public void Ds\Sequence::sort(callable $comparator = ?)
abstract public Ds\Sequence Ds\Sequence::sorted(callable $comparator = ?)
abstract public intfloat Ds\Sequence::sum()
abstract public void Ds\Sequence::unshift(mixed $values = ?)
/* Inherited methods */
public void Ds\Collection::clear()
public Ds\Collection Ds\Collection::copy()
public bool Ds\Collection::isEmpty()
public array Ds\Collection::toArray()
public int Countable::count()
public Traversable IteratorAggregate::getIterator()
public mixed JsonSerializable::jsonSerialize()
public bool ArrayAccess::offsetExists(mixed $offset)
public mixed ArrayAccess::offsetGet(mixed $offset)
public void ArrayAccess::offsetSet(mixed $offset, mixed $value)
public void ArrayAccess::offsetUnset(mixed $offset)

Changelog

Version Description
PECL ds 1.3.0 The interface now extends ArrayAccess.

Table of Contents