-
-
Notifications
You must be signed in to change notification settings - Fork 9
Open
Description
The situation often comes up that you want to demonstrate some iterator chain using ?eval. Directly writing the iterator yields bad results:

The obvious workaround is to collect into a vector:

However, this workaround is slightly problematic:
- it adds boilerplate
- it may confuse beginners, particularly with the heavy syntax (
::<Vec<_>>) - it encourages beginners to overuse vector allocations instead of iterating iterators directly
Perhaps there is a way to special-case the return value formatting for iterators? In the above example, the bot output could look like this:
1, 3, 5, 7, 9
Advantages:
- Code is simple to write, easy to read, pretty
- Output is very pleasant to look at
- No boilerplate for users
- Doesn't lead beginners to over use vector allocations
Potential difficulties:
- Tricky to implement. Requires either a hackish display trait with a specialization for iterators; OR static analysis to determine te type of the return value. Both are not great
- Introduces more "magic" to the bot. It may be hard to understand for bot users where this formatting is coming from
- What to do on long or endless iterators? (Probably best to just render an ellipsis after a certain number of items)
Metadata
Metadata
Assignees
Labels
No labels