Fix test file name typo. Update readme.

This commit is contained in:
CismonX 2018-04-22 23:06:49 +08:00
parent f2209e019d
commit 1c787a4a41
2 changed files with 17 additions and 7 deletions

View File

@ -11,8 +11,19 @@ Method names and functionalities are inspired by [Kotlin.Collections](https://ko
## 2. Documentation
### 2.1 Functionalities
See [stubs](stubs/) directory for signature of all classes and methods of this extension, with PHPDoc.
### 2.2 PHP-style access
The `Collection` class implements `ArrayAccess` and `Countable` interface internally, you can treat an instance of `Collection` as an `ArrayObject`.
* The `isset()`, `unset()` keywords can be used on elements of `Collection`.
* Elements can be accessed via property (string keys only) and bracket expression.
* `empty()`, `count()` can be used on instance of `Collection`.
* Elements can be traversed via `foreach()` keyword.
## 3. Example
Here is a simple example for how to work with arrays gracefully using this extension.
@ -27,16 +38,15 @@ $employees = [
// Trying to get an array of names of male employees,
// sorted by the descending order of their age.
$names = Collection::init($employees)
->filter(function ($it) {
return $it['sex'] == 'male';
->filter(function ($value) {
return $value['sex'] == 'male';
})
->sortedByDescending(function ($it) {
return $it['age'];
->sortedByDescending(function ($value) {
return $value['age'];
})
->map(function ($it) {
return $it['name'];
->map(function ($value) {
return $value['name'];
})
->toArray();
// You got $names == ['David', 'Benjamin', 'Bob'].
```