From 1c787a4a413b9d081dc6da70e3b970b8adfc66d2 Mon Sep 17 00:00:00 2001 From: CismonX Date: Sun, 22 Apr 2018 23:06:49 +0800 Subject: [PATCH] Fix test file name typo. Update readme. --- README.md | 24 +++++++++++++++------ tests/{022-flatten.php => 022-flatten.phpt} | 0 2 files changed, 17 insertions(+), 7 deletions(-) rename tests/{022-flatten.php => 022-flatten.phpt} (100%) diff --git a/README.md b/README.md index 4e234b2..96a9422 100644 --- a/README.md +++ b/README.md @@ -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']. ``` - diff --git a/tests/022-flatten.php b/tests/022-flatten.phpt similarity index 100% rename from tests/022-flatten.php rename to tests/022-flatten.phpt