File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed
Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff 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
2223Installation
2324------------
@@ -366,4 +367,37 @@ $limit = 1;
366367var_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```
You can’t perform that action at this time.
0 commit comments