2017 © Pedro Peláez
 

library collection

image

meekframework/collection

  • Monday, May 28, 2018
  • by nbish11
  • Repository
  • 1 Watchers
  • 0 Stars
  • 0 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 0 % Grown

The README.md

MeekFramework 'Collection' Component

Provides implementations and contracts for dealing with data structures., (*1)

The data type of the first element added to any collection implementation then becomes the only supported type for that collection instance., (*2)

Example using scalar types:, (*3)

$stack = new Meek\Collection\UnboundedStack();

$stack->push('1');  // All future push() operations will only accept the string data type.

$stack->push(2);    // Throws an InvalidArgumentException -> must be a string

Example using objects:, (*4)

class MyClass extends stdClass {}

$stack = new Meek\Collection\UnboundedStack();

$stack->push(new stdClass());   // All future push() operations will only accept instances of `stdClass`.
$stack->push(new MyClass());    // Works fine as `MyClass` is sub-classed from `stdClass`


$stack->push(new class {});    // Throws an InvalidArgumentException -> must be an instance of "stdClass"

Usage

Stack

Reversing a string using an UnboundedStack:, (*5)

$wordToReverse = 'dog';
$stack = new Meek\Collection\UnboundedStack(...str_split($wordToReverse));
$reversedWord = '';

while ($stack->size() > 0) {
    $reversedWord .= $stack->pop();
}

print $reversedWord;    // prints 'god'

Keeping track of history using a BoundedStack:, (*6)

$numberOfActionsToKeepTrackOf = 3;
$stack = new Meek\Collection\BoundedStack($numberOfActionsToKeepTrackOf);

$perform = function ($action) use ($stack) {
    $stack->push($action);
    echo sprintf('perform: %s', $action);
};

$undo = function () use ($stack) {
    $action = $stack->pop();
    echo sprintf('undo: %s', $action);
};

$perform('select all');     // prints 'perform: select all'
$perform('copy');           // prints 'perform: copy'
$perform('paste');          // prints 'perform: paste'
$undo();                    // prints 'undo: paste'
$perform('paste');          // prints 'perform: paste'

try {
    $perform('select all');
} catch (OverflowException $e) {
    // clear history and keep going or notify user that history is full
}

The Versions

28/05 2018

dev-master

9999999-dev

  Sources   Download

MIT

The Development Requires

28/05 2018

v0.3.0

0.3.0.0

  Sources   Download

MIT

The Development Requires

27/05 2018

v0.2.0

0.2.0.0

  Sources   Download

MIT

The Development Requires

27/05 2018

0.1.0

0.1.0.0

  Sources   Download

MIT

The Development Requires