Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Collector class #24

Merged
merged 6 commits into from
Sep 7, 2024
Merged

Add Collector class #24

merged 6 commits into from
Sep 7, 2024

Conversation

samsonasik
Copy link
Owner

@samsonasik samsonasik commented Sep 7, 2024

To allow collect with filtered and transformed data, for example, for data:

Before

$newArray = [];

foreach ($data as $datum) {
    if (is_string($datum)) {
        $newArray[] = trim($datum);
    }
}

After

use ArrayLookup\Collector;

$when = fn (mixed $datum): bool => is_string($datum);
$limit = 2;
$transform = fn (string $datum): string => trim($datum);

$newArray = Collector::setUp($data)
       ->when($when)
       ->withLimit(2) // optional to only collect some data provided by limit config
       ->withTransform($transform)
       ->getResults();

Closes #19

@codecov-commenter
Copy link

codecov-commenter commented Sep 7, 2024

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (d71ac82) to head (7eab4e4).

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@             Coverage Diff             @@
##                main       #24   +/-   ##
===========================================
  Coverage     100.00%   100.00%           
- Complexity        36        44    +8     
===========================================
  Files              3         4    +1     
  Lines             91       120   +29     
===========================================
+ Hits              91       120   +29     
Flag Coverage Δ
tests 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@samsonasik samsonasik merged commit d3c90d4 into main Sep 7, 2024
4 checks passed
@samsonasik samsonasik deleted the add-collector-class branch September 7, 2024 13:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Collector class
2 participants