markrogoyski / itertools-php

PHP Iteration Tools Library
MIT License
140 stars 11 forks source link

Method Single::filterUnique() added #4

Closed Smoren closed 1 year ago

Smoren commented 1 year ago
coveralls commented 1 year ago

Pull Request Test Coverage Report for Build 3922751874

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details


Totals Coverage Status
Change from base Build 3921770479: 0.09%
Covered Lines: 322
Relevant Lines: 325

💛 - Coveralls
Smoren commented 1 year ago

@markrogoyski

Hi Mark!

FYI: I moved unique-mapping logic into the separate repository: https://github.com/Smoren/unique-php

Added missing behaviors and fixed bugs during testing.

Smoren commented 1 year ago

Rebased from branch "develop".

Smoren commented 1 year ago

@markrogoyski

FYI: I've moved UniqueExtractor from unique-php to type-tools-php.

Smoren commented 1 year ago

Hi @markrogoyski

I've rebased this branch from develop and resolved conflicts.

BTW I've a little bit changed unique extracting logic in my repo.

If you find a way to include this logic to IterTools we can implement such functionality as e. g. Single::intersection() and Single::difference().

use IterTools\Single;

$lhs = [1, 2, 3, 4, 5];
$rhs = [3, 4, 5, 6, 7];

$intersection = Single::intersection($lhs, $rhs);

foreach ($intersection as $item) {
    // 3, 4, 5
}

What do you think about it?

UPD: I've rebased this branch from develop.

markrogoyski commented 1 year ago

Hi @Smoren,

Apologies for the delay in responding.

How about changing the name to distinct and drop the "filter" prefix. Distinct usually means removing duplicates, whereas unique can imply only selecting the items that only appear once.

Thanks, Mark

Smoren commented 1 year ago

Hi @markrogoyski

Thank you for your suggestion!

Summary of changes:

  1. Single::filterUnique() renamed to Single::distinct().
  2. Util\UniqueExtractor added and used in Single::distinct().
  3. FilterUniqueTest renamed to DistinctTest.
  4. Tests added for resources, generators and closures.
  5. Stream::distinct() method added and covered by tests.
  6. README updated.
Smoren commented 1 year ago

@markrogoyski

BTW, what do you think about separate namespace for distinct, intersection, difference and other operations with sets?

markrogoyski commented 1 year ago

Hi @Smoren,

What is your suggestion here. Maybe Set::distinct($data), Set::intersection($set1, $set2), etc.?

Smoren commented 1 year ago

Hi @markrogoyski,

  1. New namespace Set created.
  2. Method Single::distinct() moved into namespace Set.
  3. DistinctTest moved into Set directory.
  4. Tests of Stream::distinct() moved into separate test Stream\SetTest.
  5. README updated.
Smoren commented 1 year ago

UPD: this branch is rebased from develop.