https://github.com/mpstyle/plazy
Another functional library for PHP 7
https://github.com/mpstyle/plazy
Last synced: 6 months ago
JSON representation
Another functional library for PHP 7
- Host: GitHub
- URL: https://github.com/mpstyle/plazy
- Owner: MpStyle
- License: lgpl-3.0
- Created: 2016-08-05T14:32:09.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2016-08-06T07:39:02.000Z (over 9 years ago)
- Last Synced: 2025-06-25T07:43:56.183Z (9 months ago)
- Language: PHP
- Homepage:
- Size: 28.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# plazy
Another functional library for PHP 7.
## Quickstart
To use _plazy_ in your projects install _composer_ and add to your _composer.json_ file:
```json
"require": {
"mpstyle/plazy": "0.2.3"
}
```
Or run:
```
composer require "mpstyle/plazy"
```
## Sequence
The sequence class allows you to build up a computation out of smaller operations. It's similar to Java 8 Streams
Now we can try some of the following:
```php
Sequence::sequence(1, 2, 3, 4)->filter(even); // lazily returns 2,4
Sequence::sequence(1, 2)->map(toString); // lazily returns "1", "2"
Sequence::sequence(1, 2, 3)->take(2); // lazily returns 1,2
Sequence::sequence(1, 2, 3)->drop(2); // lazily returns 3
Sequence::sequence(1, 2, 3)->tail(); // lazily returns 2,3
Sequence::sequence(1, 2, 3)->head(); // eagerly returns 1
Sequence::sequence(1, 3, 5)->find(even); // eagerly returns none()
Sequence::sequence(1, 2, 3)->contains(2); // eagerly returns true
Sequence::sequence(1, 2, 3)->toString(":"); // eagerly returns "1:2:3"
```
## Option
Optional value - type-safe null
## Functions
plazy provides some interfaces for functional uages, such as:
- F: to transform an object to another one.
- Predicate: to filter/select/match an object.
- Validator: to validate an object.
## Developers
To run unit test, run in the root of the plazy project:
```
composer phptest
```