Anahkiasen / underscore-php

A redacted PHP port of Underscore.js with additional functions and goodies – Available for Composer and Laravel
http://anahkiasen.github.com/underscore-php/
1.12k stars 88 forks source link

Alternative to underscore-php #105

Open mpetrovich opened 6 years ago

mpetrovich commented 6 years ago

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:

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

Anahkiasen commented 6 years ago

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 commented 6 years ago

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: