Giter VIP home page Giter VIP logo

Comments (10)

orlp avatar orlp commented on June 17, 2024

To see which iterator methods we may want to add to the new ranges, I did an informal search on
Github using the following query:

language:rust NOT is:fork /\W\s*\(\s*\w*\s*\.\.=?\s*\w*\s*\)\s*.\s*method\s*\(/

I matched on anything that looks like ( <> .. <> ) or ( <> ..= <> ) that is not immediately
preceded by some identifier character, to avoid matching things like vec.drain(..).map(_).

Example for map: search.

This isn't perfect but captures a rough amount of usage. Just looking by the number of matches:

  • map: 65.8k
  • rev: 23.2k
  • collect: 9.9k
  • for_each: 8.5k
  • step_by: 8.3k
  • filter: 8.2k
  • flat_map: 4.2k
  • fold: 3.5k
  • zip: 3.4k
  • filter_map: 1.6k
  • find: 1.5k
  • chain: 1.4k
  • take_while: 1.1k
  • all: 1.1k
  • cycle: 0.7k
  • enumerate: 0.6k
  • scan: 0.4k
  • product: 0.4k
  • find_map: 0.3k
  • any: 0.3k
  • sum: 0.2k
  • take: 0.2k
  • skip: 0.1k
  • try_*: 0.1k
  • min*: 0.1k
  • max*: 0.1k
  • map_while: 0.1k
  • position: 0.1k
  • skip_while: 0.1k
  • count: 0.1k
  • reduce: 0.1k
  • nth: 0.1k
  • unzip: 0

I personally think filter is a decent cut-off, which gives the inherent methods map, rev, collect, for_each, step_by, filter.

from rust.

pitaj avatar pitaj commented on June 17, 2024

Any reason you left out step_by from your final list?

from rust.

orlp avatar orlp commented on June 17, 2024

@pitaj Nope, just a clerical error. I fixed it.

from rust.

programmerjake avatar programmerjake commented on June 17, 2024

another common method that was omitted: len() (idk how many instances since github gave an error when I tried the search)

from rust.

orlp avatar orlp commented on June 17, 2024

@programmerjake There is no len() on Iterator.

from rust.

programmerjake avatar programmerjake commented on June 17, 2024

@programmerjake There is no len() on Iterator.

there is on ExactSizeIterator: https://doc.rust-lang.org/std/ops/struct.Range.html#impl-ExactSizeIterator-for-Range%3Ci8%3E

from rust.

orlp avatar orlp commented on June 17, 2024

Right. I think honestly len probably makes sense regardless of whether an iterator implements it and/or how many people currently are calling it.

from rust.

pitaj avatar pitaj commented on June 17, 2024

I'd rather we have a better solution for len than ExactSizeIterator since, as proposed, even the new iterators for Range<u32> and RangeInclusive<i16> don't implement it.

from rust.

orlp avatar orlp commented on June 17, 2024

Ugh I forgot, there's still the problem that fn len(&self) -> usize doesn't work on ranges larger than usize, nor the 0..=usize::MAX range for usize itself.

from rust.

traviscross avatar traviscross commented on June 17, 2024

Let's continue that discussion about which methods to add in a separate issue here rather than on the tracking issue.

from rust.

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.