The Sequence interface
(No version information available, might only be in Git)
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
Table of Contents
- Ds\Sequence::allocate — Allocates enough memory for a required capacity
- Ds\Sequence::apply — Updates all values by applying a callback function to each value
- Ds\Sequence::capacity — Returns the current capacity
- Ds\Sequence::contains — Determines if the sequence contains given values
- Ds\Sequence::filter — Creates a new sequence using a callable to determine which values to include
- Ds\Sequence::find — Attempts to find a value's index
- Ds\Sequence::first — Returns the first value in the sequence
- Ds\Sequence::get — Returns the value at a given index
- Ds\Sequence::insert — Inserts values at a given index
- Ds\Sequence::join — Joins all values together as a string
- Ds\Sequence::last — Returns the last value
- Ds\Sequence::map — Returns the result of applying a callback to each value
- Ds\Sequence::merge — Returns the result of adding all given values to the sequence
- Ds\Sequence::pop — Removes and returns the last value
- Ds\Sequence::push — Adds values to the end of the sequence
- Ds\Sequence::reduce — Reduces the sequence to a single value using a callback function
- Ds\Sequence::remove — Removes and returns a value by index
- Ds\Sequence::reverse — Reverses the sequence in-place
- Ds\Sequence::reversed — Returns a reversed copy
- Ds\Sequence::rotate — Rotates the sequence by a given number of rotations
- Ds\Sequence::set — Updates a value at a given index
- Ds\Sequence::shift — Removes and returns the first value
- Ds\Sequence::slice — Returns a sub-sequence of a given range
- Ds\Sequence::sort — Sorts the sequence in-place
- Ds\Sequence::sorted — Returns a sorted copy
- Ds\Sequence::sum — Returns the sum of all values in the sequence
- Ds\Sequence::unshift — Adds values to the front of the sequence
English translation
You have asked to visit this site in English. For now, only the interface is translated, but not all the content yet.If you want to help me in translations, your contribution is welcome. All you need to do is register on the site, and send me a message asking me to add you to the group of translators, which will give you the opportunity to translate the pages you want. A link at the bottom of each translated page indicates that you are the translator, and has a link to your profile.
Thank you in advance.
Document created the 30/01/2003, last modified the 26/10/2018
Source of the printed document:https://www.gaudry.be/en/php-rf-class.ds-sequence.html
The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.
References
These references and links indicate documents consulted during the writing of this page, or which may provide additional information, but the authors of these sources can not be held responsible for the content of this page.
The author This site is solely responsible for the way in which the various concepts, and the freedoms that are taken with the reference works, are presented here. Remember that you must cross multiple source information to reduce the risk of errors.