Skip to content

Instantly share code, notes, and snippets.

@ewinslow
Last active August 29, 2015 14:10
Show Gist options
  • Save ewinslow/a6df73a5ff172c63acd1 to your computer and use it in GitHub Desktop.
Save ewinslow/a6df73a5ff172c63acd1 to your computer and use it in GitHub Desktop.
php collections interfaces
<?php
/**
* An ordered collection.
*
* could call it "Sequence"
*
* @generic V
*/
interface List extends Collection {
/**
* or nth, getNth, ...
*
* @param int $index
*
* @return V
*/
function getAt($index);
/** @return V */
function last();
}
<?php
/**
* A collection where each item has a key.
*
* aka Dictionary
*
* @generics K, V
*/
interface Map extends Collection {
/**
* @param K $key
*
* @return V
*/
function get($key);
/** @return Set<K> */
function keys();
}
<?php
/**
* Typically FIFO, but could be implemented
* as LIFO to make a Stack.
*/
interface Queue extends List {
/** @return T */
function peek();
/** @return T */
function pop();
/** @param T $item */
function push($item);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment