Last active
August 29, 2015 14:10
-
-
Save ewinslow/a6df73a5ff172c63acd1 to your computer and use it in GitHub Desktop.
php collections interfaces
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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