At minimum I would say our for loop syntax should not be based on external iterators, since it gets none of the benefits
-
Show this thread
-
Anyway this is all hypothetical: notes for the next language
1 reply 0 retweets 8 likesShow this thread -
Replying to @withoutboats
I hadn't heard of "internal vs external iteration" before I think yesterday? If I understand it correctly it's: // internal stream.for_each(|x| dbg!(x)); // external for x in stream { dbg!(x); } But feel like there might be more to it? Is it abt return types too?
1 reply 0 retweets 4 likes -
-
Replying to @ag_dubs @yoshuawuyts
Yea you’re right, it’s where for loop de sugars into the for_each example, rather than repeated calls to next
1 reply 0 retweets 5 likes -
This lets the iterator have more control over the control flow of iteration
1 reply 0 retweets 4 likes -
For example, one design could be for all the iterator-like things (streams, parallel iterators, “attached/streaming” iterators) to work with for loops, putting different bounds on the closure it desugars to (eg parallel requires that the loop body is Send, etc)
1 reply 0 retweets 5 likes -
Replying to @withoutboats @ag_dubs
Oh wow, those all sound like things that'd be neat to have. Does that mean we can't have those in Rust, or mostly that it'll be more difficult (e.g. special casing)?
1 reply 0 retweets 0 likes -
Replying to @yoshuawuyts @ag_dubs
It’s an open question. All external iterators can be made into internal iterators (which is why Iterator::for_each exists), so in theory we could probably add internal iterators in a backward compat way
1 reply 0 retweets 4 likes -
It’s relevant to consider this when working on for await loops, generators, attached streams, etc
1 reply 0 retweets 2 likes
Ah, I see. Interesting! Thanks for explaining! :D
-
-
Rust used to have internal iterators. They had their very own set of issues though, which led to their removal. Here's the relevant discussion from 2013: https://mail.mozilla.org/pipermail/rust-dev/2013-June/004364.html … And here an article on the topic from 2016:https://medium.com/@veedrac/rust-is-slow-and-i-am-the-cure-32facc0fdcb …
0 replies 0 retweets 0 likesThanks. Twitter will use this to make your timeline better. UndoUndo
-
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.