Code Monkey home page Code Monkey logo

Comments (5)

mathroc avatar mathroc commented on June 12, 2024 1

this seems nice, it's always a PITA to come working with iterator in php back from rust (or javascript with lodash)

  • find(Callable): mixed search the first item matching the predicate,
  • position(Callable): mixed search the first item matching the predicate and returns in index,
  • rightPosition(Callable): mixed same as position but searches from the right (the end) of the iterator,
  • max(): int to get the maximum value of an iterator, will be based on the spaceship operator,
  • min(): int to get the minimum value of an iterator, same mechanism than max,
    sum(): int to sum all elements in an iterator, this is a shortcut to fold with a special callable,
    product(): int to multiply all elements in an iterator, this is a shortcut to fold with a special callable,

shouldn't those return Options ? (not really sure about the last 2)

from central.

Hywan avatar Hywan commented on June 12, 2024

Note: This is somewhat very similar to nikic/iter cc @nikic if you have a feedback about your library (would you do something differently for instance? any performance issues?).

Main difference is that we are going to be full object instead of being functional.

from central.

Hywan avatar Hywan commented on June 12, 2024

@mathroc I guess sum and product must return 0 if the collection is empty. But max and min must return an option, correct! Them for find & co. I am fixing it. Thanks for the detailed look!

from central.

mathroc avatar mathroc commented on June 12, 2024

I'm ok for sum returning 0, however I'm not sure about product, I think it should return 1 (the identity element)

so that $a->product() * $b->product() === $a->chain($b)->product() is always true (as it is for sum)

from central.

Hywan avatar Hywan commented on June 12, 2024

You're correct! I reckon I should sleep more…

from central.

Related Issues (20)

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.