Giter VIP home page Giter VIP logo

Comments (11)

Smoren avatar Smoren commented on July 20, 2024

Hi @markrogoyski,

Thank you very much for this topic! There are great ideas here and I'll start to implement some of them.

For the beginning I'll take peek(), if you don't mind (UPD: I've added PR with peek methods implementation: #40).

BTW, what about adding $offset param into skip() method to start skipping elements not from the beginning of an iterable?

public static function skip(iterable $data, int $count, int $offset = 0): \Generator

foreach (Single::skip([1, 2, 3, 4, 5, 6, 7], 3, 2) as $item) {
    // 1, 2, 6, 7
}

from itertools-php.

markrogoyski avatar markrogoyski commented on July 20, 2024

Hi @Smoren,

For skip, I think as long as the offset is optional and defaults to 0 then that works.

from itertools-php.

Smoren avatar Smoren commented on July 20, 2024

Thanks, @markrogoyski, so the next method I'll implement is skip().

UPD: I've added PR #41 with functionality of skip().

from itertools-php.

Smoren avatar Smoren commented on July 20, 2024

Hi @markrogoyski,

What do you think about implementation of subslices()?

foreach (Single::subslices([1, 2, 3] as $slice) {
    // [1], [2], [3], [1, 2], [2, 3], [1, 2, 3]
}

BTW: I think it would be nice to have implemented method names strikethrough in this thread.

from itertools-php.

Smoren avatar Smoren commented on July 20, 2024

Hi @markrogoyski,

There is iter package.

What do you think about implementing some methods which are implemented in iter
but missing in IterTools PHP?

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

from itertools-php.

Smoren avatar Smoren commented on July 20, 2024

Hi @markrogoyski,

I've implemented some methods from this topic:

  • Reduce::toRandomValue() (#42);
  • Summary::isEmpty() (#43).

from itertools-php.

Smoren avatar Smoren commented on July 20, 2024

Hi @markrogoyski,

I've added and tested Summary::allUnique() method (#44).

from itertools-php.

Smoren avatar Smoren commented on July 20, 2024

Hi @markrogoyski,

I've added and tested Set::union() method (#45).

from itertools-php.

Smoren avatar Smoren commented on July 20, 2024

Hi @markrogoyski,

I've added and tested Reduce::toNth() method (#47).

from itertools-php.

Smoren avatar Smoren commented on July 20, 2024

Hi @markrogoyski,

What do you think about the implementation of zipFilled() function in IterTools PHP like I have done it in IterTools TS?

from itertools-php.

markrogoyski avatar markrogoyski commented on July 20, 2024

Hi @Smoren,

I made a choice to not add a fill variable to zipLongest because it would have to be the first parameter, and even if you don't want a filler, you'd have to add that variable.

Interestingly, in PHP 8.1, you can have a named parameter after unpacking a variadic parameter, so I think you could do something like:

Multi::zipLongest($iter1, $iter2, fillValue: 'filler');

where the method signature is:

public function zipLongest(iterable ...$iterables, $fillValue = null);

Then it behaves and sort of looks like how you'd do it in Python.

Right now 7.4 is the minimum version. One option is to just wait a couple years and when I bump up the minimum version to something >= 8.1, then add it to zipLongest. Another option is to do like you suggest and implement a separate function like zipFilled.

Probably simplest to implement zipFilled as it keeps the interface to zipLongest simple.

from itertools-php.

Related Issues (6)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.