Skip to content

Consider formatting Iterator specially in ?eval? #29

@kangalio

Description

@kangalio

The situation often comes up that you want to demonstrate some iterator chain using ?eval. Directly writing the iterator yields bad results:
Screenshot_20210128_113723

The obvious workaround is to collect into a vector:
Screenshot_20210128_113756

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

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions