ziadoz / awesome-php

A curated list of amazingly awesome PHP libraries, resources and shiny things.
Do What The F*ck You Want To Public License
30.59k stars 5.04k forks source link

Add IterTools PHP to Architectural section #1217

Closed Smoren closed 6 months ago

Smoren commented 1 year ago

Added IterTools PHP - A library that provides functionality for working with iterable entities (similar to itertools library in Python).

llaville commented 1 year ago

Seems equivalent to https://github.com/nikic/iter !

Smoren commented 1 year ago

@llaville, thanks for feedback!

PHP iterTools is similar to iter but not equivalent because it provides a lot more functionality. Please look at the documentation in the README of the project.

Moreover, it provides fluent interface to make chain operations on iterables (Stream class):

$result = Stream::of([1, 1, 2, 2, 3, 4, 5])
    ->distinct()                 // [1, 2, 3, 4, 5]
    ->map(fn ($x) => $x**2)      // [1, 4, 9, 16, 25]
    ->filter(fn ($x) => $x < 10) // [1, 4, 9]
    ->toSum();                   // 14
Smoren commented 1 year ago

Here is a comparison:

IterTools PHP iter
Multi::chain chain
Multi::zip zip
Multi::zipEqual -
Multi::zipLongest -
- zipKeyValue
Single::chunkwise chunk
Single::chunkwiseOverlap -
- chunkWithKeys
Single::compress -
Single::compressAssociative -
- drop
Single::dropWhile dropWhile
- enumerate, toPairs (equivalents of each other, but not equivalents of Single::pairwise)
Single::filter filter
Single::filterTrue -
Single::filterFalse -
Single::filterKeys -
Single::flatMap flatMap
Single::flatten flatten
- flip
Single::groupBy -
- keys
Single::limit -
Single::map map
- mapKeys
- mapWithKeys
Single::pairwise -
- product
Single::reindex reindex
Single::repeat repeat
Single::reverse -
- recurse
Single::slice slice
Single::string split
- take
Single::takeWhile takeWhile
Infinite::count range
Infinite::cycle -
Infinite::repeat -
Random::choice -
Random::coinFlip -
Random::number -
Random::percentage -
Random::rockPaperScissors -
Math::runningAverage -
Math::runningDifference -
Math::runningMax -
Math::runningMin -
Math::runningProduct -
Math::runningTotal -
Set::distinct -
Set::intersection -
Set::intersectionCoercive -
Set::partialIntersection -
Set::partialIntersectionCoercive -
Set::symmetricDifference -
Set::symmetricDifferenceCoercive -
Sort::asort -
Sort::sort -
File::readCsv -
File::readLines -
- fromPairs
Transform::tee -
Transform::toArray toArray
Transform::toAssociativeArray toArrayWithKeys
Transform::toIterator toIter
Summary::allMatch all
Summary::anyMatch any
Summary::arePermutations -
Summary::arePermutationsCoercive -
Summary::exactlyN -
- isEmpty
- isIterable
Stream::callForEach apply
Summary::isPartitioned -
Summary::isSorted -
Summary::isReversed -
Summary::noneMatch -
Summary::same -
Summary::sameCount -
- reductions
- search
Reduce::toAverage -
Reduce::toCount count
Reduce::toFirst -
Reduce::toFirstAndLast -
Reduce::toLast -
Reduce::toMax -
Reduce::toMin -
Reduce::toMinMax -
Reduce::toProduct -
Reduce::toRange -
Reduce::toString join
Reduce::toSum -
Reduce::toValue reduce
- values
llaville commented 1 year ago

@Smoren thanks for compare report

Smoren commented 1 year ago

BTW, IterTools PHP is mentioned in PHP Annotated February 2023 by JetBrains.

Smoren commented 5 months ago

@ziadoz thank you for merging this PR!