Skip to content

adapters::cartesian_product does a bit too much #295

@reuvenpo

Description

@reuvenpo

Looking at how pub fn cartesian_product<I, J>(mut i: I, j: J) -> Product<I, J> initialises Product, one can see that it yields the first item in i.
Wouldn't it be better if Product.a_cur was an Option<Option<I::Item>> and initialized as None, rather than initializing it by starting the consumption of i?

This may cause problems if iteration over i has side effects.

Same with Product.b too. No reason to clone it ahead of time.

I haven't looked deep into at the implementation of multi_cartesian_product but it may be a similar situation there too.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions