Skip to content
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

Add core::repeat(int, fn()) function #1703

Closed
brson opened this issue Jan 29, 2012 · 11 comments
Closed

Add core::repeat(int, fn()) function #1703

brson opened this issue Jan 29, 2012 · 11 comments
Labels
C-enhancement Category: An issue proposing an enhancement or a PR with one. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.

Comments

@brson
Copy link
Contributor

brson commented Jan 29, 2012

Sometimes you just want to do something some number of times. There's no real concise way to express that right now.

@pwoolcoc
Copy link
Contributor

Where would be the best place to put this function? An existing file in libcore/? A "repeat.rs" file in libcore? or a more general "iterator.rs" file in libcore?

@brson
Copy link
Contributor Author

brson commented Jan 30, 2012

There isn't an existing place that makes sense. I was thinking of just putting it into core.rs, but that does pull it into the global scope. I hate to dump it into something as generic as util.rs because nobody will ever find it.

@pwoolcoc
Copy link
Contributor

making an "iter.rs" or "iterator.rs" might make a bit more sense...though "import core::iter::repeat" might be a little word-y.

@brson
Copy link
Contributor Author

brson commented Jan 30, 2012

If you are going to go that route then please have a look at the iterator library nmatsakis is working on and which he intends to merge into core or std: https://github.com/nikomatsakis/rust-iter

Repeat doesn't strictly have anything to do with an iterator type, but it clearly has to do with iteration. Maybe we can get @nikomatsakis's opinion

@nikomatsakis
Copy link
Contributor

I could add it to the iter library, I suppose!

As an alternative, what about allowing block parameters to be named "_", meaning "I really don't use this."

Then you could write:

uint::range(0, 10) {|_|
}

which seems marginally nicer than |_i|. And it preserves the invariant that an iterator is something that ends with a block with a single argument. But I don't really care. I guess repeat(10) {|| ... } reads nicer.

@brson
Copy link
Contributor Author

brson commented Jan 30, 2012

I do think being able to write |_| would be nice regardless - it comes up frequently.

@pwoolcoc
Copy link
Contributor

I sent @nikomatsakis a pull request for the repeat function.

@kud1ing
Copy link

kud1ing commented Jan 31, 2012

@nikomatsakis: When do you plan to integrate your "iter" module in libcore? The module "str" has has some duplicate functions doing basically the same thing, differing only in either "returning" a list of strings or an iterator. Having iter::to_list in libcore we could settle on only the iteration-versions.

@nikomatsakis
Copy link
Contributor

I plan to merge it today in some form.null

@kud1ing
Copy link

kud1ing commented Jan 31, 2012

That would be awesome.

@brson
Copy link
Contributor Author

brson commented Mar 13, 2012

This is done.

@brson brson closed this as completed Mar 13, 2012
flip1995 pushed a commit to flip1995/rust that referenced this issue Apr 22, 2021
…ffen

Invalid null usage v2

This is continuation of rust-lang#6192 after inactivity.

I plan to move paths into the compiler as diagnostic items after this is merged.

fixes rust-lang#1703
changelog: none
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: An issue proposing an enhancement or a PR with one. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
Projects
None yet
Development

No branches or pull requests

4 participants