-
Notifications
You must be signed in to change notification settings - Fork 13.3k
usability issue: connect()
-like functionality is only available on slices, not on Iterator(Item=Str)
#22754
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
Comments
In Python this is basically just implemented on the equivalent of |
I think the point is that one can pass an iterable, whereas in Rust this is currently not possible. Also there seems to be no reason to not have such functionality readily available. Of course I might be totally mistaken there given my greenling status with Rust. Nonetheless I try to point out a usability issue, and addressing it will make using Rust easier in the given context. |
I just addressed your
by pointing out that Python does that exact thing in its "connect" ( |
I think it would be comparable if one would have to write something like this: Also I hope what I wrote makes at least some sense, I don't know if I this issue is complying with requirements, or if it is at the right spot even. |
And note, the string-joining functionality on iterators was implemented by a trait in collect-rs. I've imported it into itertools, so at least it's available there. |
@bluss Shouldn't |
Thank you - the newly added @bluss About 2) Isn't there a rewindable iterator Trait somewhere, which would allow to traverse sequences multiple times. In that case, one could have one run to compute the required string size, and a second one to fill in the result string. |
@Byron That would probably be a |
True ! It could be that easy ! With that in mind, maybe |
Triage: no change here. The |
Now that a crate implements this, it could be considered fixed. Adding it to the standard library would likely require an RFC. |
I agree with what has been written -- the |
In other languages, this kind of functionality is easily achieved:
In Rust, this currently only works on slices and vectors. However, in generic code, one usually has an iterator only, and I believe it should be simple to connect such an iterator if the item type is compatible.
Otherwise I fear people will start to throw in an intermediate
collect::<Vec<String>>()
call, which has performance implications.All details, code, and the current workaround using
itertools.intersperse()
can be found in the respective question on stackoverflow.Please note that this seems to be related to a more general issue, namely that some useful functionality is not implemented on Iterator, even though it could be: http://internals.rust-lang.org/t/add-dedup-for-iterator/1567 .
Meta
rustc 1.0.0-nightly (522d09d 2015-02-19) (built 2015-02-19)
binary: rustc
commit-hash: 522d09d
commit-date: 2015-02-19
build-date: 2015-02-19
host: x86_64-apple-darwin
release: 1.0.0-nightly
The text was updated successfully, but these errors were encountered: