Skip to content
This repository has been archived by the owner on Jul 6, 2019. It is now read-only.

Alternative to underscore-php #105

Open
mpetrovich opened this issue Aug 20, 2018 · 2 comments
Open

Alternative to underscore-php #105

mpetrovich opened this issue Aug 20, 2018 · 2 comments

Comments

@mpetrovich
Copy link

mpetrovich commented Aug 20, 2018

Frustrated by the lack of updates, we built our own Underscore-like functional programming library since none of the tools out there were maintained, easy to use, or well-documented: https://github.com/nextbigsoundinc/dash

$avgMaleAge = Dash\chain([
	['name' => 'John', 'age' => 12, 'gender' => 'male'],
	['name' => 'Jane', 'age' => 34, 'gender' => 'female'],
	['name' => 'Pete', 'age' => 23, 'gender' => 'male'],
	['name' => 'Mark', 'age' => 11, 'gender' => 'male'],
	['name' => 'Mary', 'age' => 42, 'gender' => 'female'],
])
->filter(['gender', 'male'])
->map('age')
->average()
->value();

echo "Average male age is $avgMaleAge.";

Highlights:

  • Many data types supported: arrays, objects, generators (coming soon), Traversable, DirectoryIterator, and more
  • Chaining
  • Currying
  • Lazy evaluation
  • Custom operations
  • Well-tested: Comprehensive tests with nearly 3,000 test cases and 100% code coverage

I hope it can be useful to someone. Feedback welcome!

@Anahkiasen
Copy link
Owner

Anahkiasen commented Aug 26, 2018

Very nice ! If some of you have some other similar alternatives you can maybe list them here and I can add some to the README for other people landing here

@mpetrovich
Copy link
Author

The lack of viable alternatives is what prompted us to create our own library. Nonetheless, there are a couple that might be useful depending on your needs:

  • maciejczyzewski/bottomline: Relatively well-updated but only seems to work with arrays and not generic iterables
  • nikic/iter: Works with any iterable (including generators) but uses composition instead of chaining

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants