ecks/ecks

An array decorator that adds a fluid functional interface similar to that of an Array in Ruby. Inspired by underscore.php.

0.0.12 2015-06-10 15:24 UTC

This package is not auto-updated.

Last update: 2024-04-21 05:29:02 UTC


README

Ecks is...

  • inspired by underscore.php
  • far from complete
  • highly likely to be broken

Ecks will be great because...

  • it will have a "fluid" (i.e. call-chaining) interface, but without underscore.php's need for chain() and value() methods
  • it provides a KeyValuePair class which callbacks may return. Unlike underscore.php, this can give client code control over the indexing of a result array
  • instances of Ecks will be (almost, see below) interchangeable with arrays
  • it includes an array decorator (which implements Ecks' array interchangeability) that you can reuse for your own classes

Depending on what you want to do with Ecks, it may be a waste of your time because...

  • PHP has global functions that operate on arrays and that check that a "native" PHP array is passed to them. Examples of this kind of function are array_intersect() and array_map(). If you inject an instance of Ecks in to your code where you would normally inject an array, and if you use this kind of global function in that code, then your code will fall over. You can always get the undecorated (i.e. unwrapped) array out of an instance of Ecks using Ecks::asArray(). It's up to you whether this meets your requirements.
  • Most of Ecks' methods are already available for native arrays as global PHP functions. A few of them are (or will be) new or different. For instance PHP's array_diff is dependent on the order of arguments. Ecks::diff() will not be. (It will return all elements that are not common to both arrays.) A few of Ecks' planned methods do not exist at all as global functions in PHP, e.g. Ecks::reduceRight().