Comments (10)
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.8krev
: 23.2kcollect
: 9.9kfor_each
: 8.5kstep_by
: 8.3kfilter
: 8.2kflat_map
: 4.2kfold
: 3.5kzip
: 3.4kfilter_map
: 1.6kfind
: 1.5kchain
: 1.4ktake_while
: 1.1kall
: 1.1kcycle
: 0.7kenumerate
: 0.6kscan
: 0.4kproduct
: 0.4kfind_map
: 0.3kany
: 0.3ksum
: 0.2ktake
: 0.2kskip
: 0.1ktry_*
: 0.1kmin*
: 0.1kmax*
: 0.1kmap_while
: 0.1kposition
: 0.1kskip_while
: 0.1kcount
: 0.1kreduce
: 0.1knth
: 0.1kunzip
: 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.
Any reason you left out step_by
from your final list?
from rust.
@pitaj Nope, just a clerical error. I fixed it.
from rust.
another common method that was omitted: len()
(idk how many instances since github gave an error when I tried the search)
from rust.
@programmerjake There is no len()
on Iterator
.
from rust.
@programmerjake There is no
len()
onIterator
.
there is on ExactSizeIterator
: https://doc.rust-lang.org/std/ops/struct.Range.html#impl-ExactSizeIterator-for-Range%3Ci8%3E
from rust.
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.
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.
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.
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)
- ICE: `assertion failed: !value.has_infer()` in `rustc_hir_typeck/src/writeback.rs`
- Illegal instruction when cross compile HOT 14
- conflicting impl since nightly-2024-05-01 HOT 9
- flaky aborts with `lto=thin` on Windows in `--release` HOT 11
- ICE: `!self.intercrate` HOT 4
- ICE: `invalid asymmetric binary op`
- ICE: `FloatToFloat/FloatToInt cast: source type usize is not a float type` HOT 2
- ICE; `tried to combine ConstKind::Infer/ConstKind::Infer(InferConst::Var): ?0e: bool and ?0c: Dimension` HOT 1
- ICE: `layout mismatch for result of MulWithOverflow`
- Unexpected float value when casted from `f32` to `f64` HOT 4
- inline-asm x86 CR0 register not recognized depending on the instruction used HOT 1
- rustc panic with -C prefer-dynamic=yes and -C rpath=yes
- Tracking Issue for RFC 3624: Supertrait item shadowing v2 HOT 1
- Misleading suggestion to add bound to type alias parameter HOT 1
- ICE: `expected bits of isize, got Ty(3_isize,)`
- ICE: `called Option::unwrap() on a None value in rustc_middle/src/mir/tcx.rs`
- Using `-C lto=thin` and `-C no-prepopulate-passes` at the same time for windows target , report link error: undefined symbol
- Add cfg Support for Distinguishing WASI Targets HOT 4
- Bumping beta compiler can require nuking `build/` to unstuck `x` HOT 2
- ICE: `offset of unsized field (type dyn [Binder(Trait(MyTrait<'_>), [])] + '{erased}) cannot be computed statically` with `feature(builtin_syntax)` HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rust.