update page now
Longhorn PHP 2026 - Call For Papers

The Sequence interface

(PECL ds >= 1.0.0)

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:

Interface synopsis

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

Changelog

Version Description
PECL ds 1.3.0 The interface now extends ArrayAccess.

Table of Contents

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top