Skip to content

It's surprising that Iterator::len consumes the iterator #14678

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
erickt opened this issue Jun 5, 2014 · 2 comments
Closed

It's surprising that Iterator::len consumes the iterator #14678

erickt opened this issue Jun 5, 2014 · 2 comments

Comments

@erickt
Copy link
Contributor

erickt commented Jun 5, 2014

The method Iterator::len() is surprising, as all the other uses of len() do not consume the value. len() would make more sense to be called count(), but that would collide with the current Iterator::count(|T| -> bool) -> unit method. That method, however, is a bit redundant, and can be easily replaced with iter.filter(|x| x < 5).count(). After this change, we could then define the len() method on iter::ExactSize.

@aturon aturon added the A-libs label Jun 5, 2014
@aturon
Copy link
Member

aturon commented Jun 5, 2014

+1, this sounds great.

@sfackler
Copy link
Member

sfackler commented Jun 5, 2014

+1

aturon added a commit to aturon/rust that referenced this issue Jun 6, 2014
This commit carries out the request from issue rust-lang#14678:

> The method `Iterator::len()` is surprising, as all the other uses of
> `len()` do not consume the value. `len()` would make more sense to be
> called `count()`, but that would collide with the current
> `Iterator::count(|T| -> bool) -> unit` method. That method, however, is
> a bit redundant, and can be easily replaced with
> `iter.filter(|x| x < 5).count()`.
> After this change, we could then define the `len()` method
> on `iter::ExactSize`.

Closes rust-lang#14678.

[breaking-change]
@aturon aturon closed this as completed in 1bde6e3 Jun 7, 2014
mcpherrinm pushed a commit to mcpherrinm/rust that referenced this issue Jun 10, 2014
This commit carries out the request from issue rust-lang#14678:

> The method `Iterator::len()` is surprising, as all the other uses of
> `len()` do not consume the value. `len()` would make more sense to be
> called `count()`, but that would collide with the current
> `Iterator::count(|T| -> bool) -> unit` method. That method, however, is
> a bit redundant, and can be easily replaced with
> `iter.filter(|x| x < 5).count()`.
> After this change, we could then define the `len()` method
> on `iter::ExactSize`.

Closes rust-lang#14678.

[breaking-change]
bors added a commit to rust-lang-ci/rust that referenced this issue Jun 5, 2023
fix: Fix restart server button trying to start instead of restart the server
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants