Skip to content

Commit 3e1f841

Browse files
committed
add documentation
1 parent a9607b5 commit 3e1f841

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Features
1818
- [x] Verify at least times: `once()`, `twice()`, `times()`
1919
- [x] Verify exact times: `once()`, `twice()`, `times()`
2020
- [x] Search data: `first()`, `last()`, `rows()`
21+
- [x] Collect data with filter and transform
2122

2223
Installation
2324
------------
@@ -366,4 +367,37 @@ $limit = 1;
366367
var_dump(
367368
Finder::rows($data, $filter, limit: $limit)
368369
); // [1]
370+
```
371+
372+
**4. Collector**
373+
---------------
374+
375+
It collect filtered data, with new transformed each data found:
376+
377+
**Before**
378+
379+
```php
380+
$newArray = [];
381+
382+
foreach ($data as $datum) {
383+
if (is_string($datum)) {
384+
$newArray[] = trim($datum);
385+
}
386+
}
387+
```
388+
389+
**After**
390+
391+
```php
392+
use ArrayLookup::Collector;
393+
394+
$when = fn ($datum): bool => is_string($datum);
395+
$limit = 2;
396+
$transform = fn ($datum): string => trim($datum);
397+
398+
$newArray = Collector::setUp($data)
399+
->when($when)
400+
->withLimit(2) // optional to only collect some data provided by limit config
401+
->withTransform($transform)
402+
->getResults();
369403
```

0 commit comments

Comments
 (0)