Functional programming for PHP with a syntax that makes sense. Dependencies-free except for mbstring.
Focuses on concise, clean and intuitive syntax. You don't have to learn "promises", "object types", "carriers" or any other high rocket science - just do it:
S(array('foo' => 'bar', 123 => 987))->keys()->up()->get(); //=> array('FOO', '123')
The only thing you will want to learn are Callbacks - because if you do it will make your code much more concise:
S(array('foo' => 'bar', 123 => 987), 'S.#up#') //=> array('FOO', '123')
Squall follows jQuery's implicit iteration approach meaning that most of its functions accept both scalar and array/object values returning scalars and arrays correspondingly:
Licensed in public domain. Visit author's homepage at http://proger.me.
You only need
squall.php. After it's
Squall\init() to create aliases for its functions (you don't have to if you will refer to them under its namespace -
include 'squall.php'; Squall\initEx(); echo S::capitalize('squall it');
You can alias Squall to another namespace:
Squall\initEx('UnderThisNS'); echo UnderThisNS\S::capitalize('squall it');
...and/or with another class name:
// for global Squall\initEx('', 'Sq'); // for NS\ Squall\initEx('NS', 'Sq'); echo NS\Sq::capitalize('squall it'); // Main function is aliased as well. echo NS\Sq(array('squall it'));
S() function is twofold:
- with 1 parameter it creates a chained version of data passed to it (usually an array/object); you can call any Squall function (static methods
S($data)->keys()and then retrieve produced data with
- with 2 parameters it's an alias to
There is no difference between calling static
S::func() and intance
S()->func() except that you don't have to provide the data as the first argument.
Squall expands on regular PHP callable format adding pipes, extra parameters, evaluations and more while retaining original compatibility (any callable is valid Squall callback but vice versa might not be true).
In general you can not care about custom callbacks if you're happy with what they can provide. Otherwise you might learn how to twist calls and shorten your code with a little extra effort:
$data = array(' fBzR ' => 1, 'XrLf ' => 2); S::map($data, array('|#trim#|strtolower|str_rot13')); //=> array(' fBzR ' => 'some', 'XrLf ' => 'keys')
Help text is yet to be written, for now you can find a draft here. Drop a line if you're interested.