# A note about the design of itertools crate

**URL:** <https://internals.rust-lang.org/t/a-note-about-the-design-of-itertools-crate/8675>\
**Category:** libs\
**Created:** [October 25, 2018, 11:56am UTC](https://internals.rust-lang.org/t/a-note-about-the-design-of-itertools-crate/8675 "2018-10-25T11:56:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![leonardo](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/leonardo/32/1344_2.png) [@leonardo](https://internals.rust-lang.org/u/leonardo)\
**Post date:** [October 25, 2018, 11:56am UTC](https://internals.rust-lang.org/t/a-note-about-the-design-of-itertools-crate/8675/1 "2018-10-25T11:56:11Z")

</div>

This issue is about moving some Clippy lints into Rustc where they probably belong (but I suspect this issue will need to be split into several issues):

> <https://github.com/rust-lang/rust/issues/53224>

Similarly, I’d like in the stdlib some of the handy things currently in the Itertools crate (but there are some backwards compatibility problems in doing this, see what happened to the flatten() method):

[https://crates.io/crates/itertools](https://crates.io/crates/itertools)

But to me some of the things of itertools have a design problem that the Rust stdlib doesn’t have. (And I discuss this here instead of the Github page of itertools because I think some itertools things should be moved into the rust stdlib). An example of this problem is visible in the zip\_longest method:

[https://docs.rs/itertools/0.7.8/itertools/trait.Itertools.html#method.zip\_longest](https://docs.rs/itertools/0.7.8/itertools/trait.Itertools.html#method.zip_longest)

It’s similar to the function with the same name in the Python stdlib:

[https://docs.python.org/3.0/library/itertools.html#itertools.zip\_longest](https://docs.python.org/3.0/library/itertools.html#itertools.zip_longest)

(Note: the API of Python zip\_longest has a problem, so here I am not saying that it’s better than the Rust version).

The Rust method yields EitherOrBoth structs:

[https://docs.rs/itertools/0.7.8/itertools/enum.EitherOrBoth.html](https://docs.rs/itertools/0.7.8/itertools/enum.EitherOrBoth.html)

In my opinion zip\_longest is a useful method, but I think a standard library should reduce the infrastructure, reduce the number of things (and data structures) to remember. I understand that EitherOrBoth makes the API types of zip\_longest more precise, but they add things to remember or to look into the documentation. So I think I’d like Rust zip\_longest to return something that doesn’t need to define a new type like EitherOrBoth, something like:

`(Option<T>, Option<T>)`

In the Rust Itertools there are other similar examples of specialized return types that I think are similarly a problem, I think library functions should use standard types as much as possible:

[https://docs.rs/itertools/0.7.8/itertools/enum.MinMaxResult.html](https://docs.rs/itertools/0.7.8/itertools/enum.MinMaxResult.html)

---

<div class="post-metadata">

**Author:** ![scottmcm](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/scottmcm/32/2355_2.png) [@scottmcm](https://internals.rust-lang.org/u/scottmcm)\
**Post date:** [October 25, 2018, 4:28pm UTC](https://internals.rust-lang.org/t/a-note-about-the-design-of-itertools-crate/8675/2 "2018-10-25T16:28:07Z")

</div>

> [@leonardo](#):
>
> [itertools::MinMaxResult - Rust](https://docs.rs/itertools/0.7.8/itertools/enum.MinMaxResult.html)

Since you mentioned this type, how would you solve the reason this exists? Are you saying you just wouldn't support non-`Clone` types in `.min_max()`?

(Now that enum layout is a thing, maybe it would be better as `Option<Something<T>>`, but there's still a good reason for an enum here.)

---

<div class="post-metadata">

**Author:** ![leonardo](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/leonardo/32/1344_2.png) [@leonardo](https://internals.rust-lang.org/u/leonardo)\
**Post date:** [October 25, 2018, 4:34pm UTC](https://internals.rust-lang.org/t/a-note-about-the-design-of-itertools-crate/8675/3 "2018-10-25T16:34:29Z")

</div>

> [@scottmcm](#):
>
> but there’s still a good reason for an enum here.

Right.

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/system/32/14092_2.png) [@system](https://internals.rust-lang.org/u/system)\
**Post date:** [March 25, 2019, 8:31am UTC](https://internals.rust-lang.org/t/a-note-about-the-design-of-itertools-crate/8675/4 "2019-03-25T08:31:03Z")

</div>

Closed on March 25, 2019, 8:31am UTC

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
