2017 © Pedro Peláez
 

library hooray

Fall in love with arrays all over again

image

wemash/hooray

Fall in love with arrays all over again

  • Tuesday, April 7, 2015
  • by kpullen
  • Repository
  • 1 Watchers
  • 0 Stars
  • 7 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 4 Versions
  • 0 % Grown

The README.md

hooray!

In the long, long ago there were just arrays, and functions to handle them. That was cool, but the functions were scattered all over the floor and their argument orders weren't all that orderly. Then @sancho had a great idea! Take the functions, order their arguments a little better, and make them chainable., (*1)

Wrap, transform, realize

Hooray is all about giving you the tools you need to work on arrays, in the form of transformations. The transformations are hung off a Hooray object, which you wrap around your array. When you are all done, just get your new array out the other end. Here is an example:, (*2)

$> hooray([1, 2, 3])
   ->map(function(thing) { return thing + 1; })
   ->realize();
$> [2, 3 4]

Hooray accepts arrays, or just a list of arguments if that's all you've got, so put those brackets away:, (*3)

$> hooray(1, 2, 3)
   ->realize();
$> [1, 2, 3]

Hooray also accepts other hooray objects, so don't worry about double wrapping:, (*4)

$> hooray(hooray(1, 2, 3))
   ->realize();
$> [1, 2, 3]

So, let's say you've been working with hooray, and so far it has solved all your problems. Now you come across a problem that would totally be solved if you could Just. Invoke. A. Transform! Well, sure, you can do that:, (*5)

$> Chain::add(
     "reticulateTheSplines",
     function($data, $arg1, $arg2) {
        // Reticulate some splines right here...
        return ["RE", "TIC", "ULATED"];
     });
$> hooray(1, 2, 3)
   ->reticulateTheSplines($arg1, $arg2)
   ->realize();
$> ["RE", "TIC", "ULATED"]

As you can see, a call to Chain::add created a new link that can immediately be invoked from any instance of hooray. What's more, that link can accept arguments, and the actual array hooray is wrapping gets prepended to the argument list before invocation. The link is then free to return whatevs. It's expected that transformations added through Chain::add return an array though. If you want to return something other than an array, use Chain::addTerminal., (*6)

Using the library

  1. git clone https://github.com/wemash/hooray
  2. phing package
  3. cp hooray.phar /var/www/wherever/you/want

or....., (*7)

  1. composer require wemash/hooray
  2. composer update
  3. composer install

The Versions

07/04 2015

dev-master

9999999-dev https://hooray.github.io

Fall in love with arrays all over again

  Sources   Download

GPL-2.0

The Requires

  • php >=5.4.0

 

The Development Requires

arrays utilities

07/04 2015

0.85.4

0.85.4.0 https://hooray.github.io

Fall in love with arrays all over again

  Sources   Download

GPL-2.0

The Requires

  • php >=5.4.0

 

The Development Requires

arrays utilities

07/04 2015

0.85.3

0.85.3.0 https://hooray.github.io

Fall in love with arrays all over again

  Sources   Download

GPL-2.0

The Requires

  • php >=5.4.0

 

The Development Requires

arrays utilities

02/04 2015

0.85.2

0.85.2.0 https://hooray.github.io

Fall in love with arrays all over again

  Sources   Download

GPL-2.0

The Requires

  • php >=5.4.0

 

The Development Requires

arrays utilities