Skip to content
This repository was archived by the owner on Sep 12, 2018. It is now read-only.
This repository was archived by the owner on Sep 12, 2018. It is now read-only.

Improve pattern for finite-length iterators in flat_map expansions #261

@ncalexan

Description

@ncalexan

There are a bunch of places where we want to turn a collection of tuples (like Vec<(A, B, C)>) into a flat iterator, like A1, B1, C1, A2, B2, C2, .... The pattern we're using right now is to combine flat_map and std::iter::once, like:

collection.flat_map(|(a, b)| once(a).chain(once(b)))

That avoids heap allocation in favour of stack allocation, but gets pretty gnarly when the tuple length increases. For example:

This ticket tracks doing something better. Perhaps a few helper functions (like once_2 and once_3?), or impl (A, B) { fn once(...) { } }, or a macro to at least make the callsite easier to read.

This is probably not a good first bug unless you're strong in Rust, because some taste is required to determine what's better than the pattern we have now.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions