rodrigodornelles/php-array-lib
simple libary for functional programing paradigm with arrays
Features
- Test driven development style (TDD)
- PHP version compatibility 5.4 at 8.2
- Make your code cleaner and more readable
- Adds new methods to manipulate arrays (Inspired by ruby, js and other langs)
How to Use
use ArrayCreate; # if you using namespaces
$myNewArray = ArrayCreate::from($myOriginalArray) # instantiate pipeline class
->map(someItemFunction) # first function to iterate on each item
->map(anotherItemFunction) # next function to iterate on each item
->filter(anotherItemFunction2) # next function to filter on each item
->construct(); # returns new array
Examples
side by side comparison
Make an algorithm that sorts an array, removes the numbers not divisible by 3, and shows the result of each multiplied by 2 and separated by commas.
Libary Functional |
Native Functional |
Structured |
---|---|---|
Installation
With Composer
The preferred way to install this extension is through composer.
Either run
$ composer require dynamikaweb/php-brazil-info "~1.0.0"
or add
"rodrigodornelles/php-array-lib": "~1.0.0"
to the require
section of your composer.json
file.
Without Composer
Step 1
Download libary in https://github.com/RodrigoDornelles/php-array-lib/releases
Step 2
Extract the file into your libraries folder
Step 3
Import the main class
require_once __DIR__.'/path/to/my/libaries/php-array-lib/src/ArrayCreate.php';