itertools icon indicating copy to clipboard operation
itertools copied to clipboard

Feature request: into_group_btreemap

Open HollayHorvath opened this issue 4 years ago • 8 comments

A BTreeMap version of the into_group* function group would be a nice addition.

The idea is that sometimes working with Hash is not feasible or even impossible, e.g. when you have to work with float-based datatypes as key or you would like to group your data by some custom criteria without wrapping the type and implementing custom Hash.

The into_group_btreemap() and into_group_btreemap_by() functions should work similarly how into_group_map() and into_group_btreemap_by() work, but would require K: Ord + Eq instead of K: Hash + Eq and would return BTreeMap<K, Vec<V>> instead of HashMap<K, Vec<V>>.

I have the code patched into my codebase, so I can also start a PR is this feature is required.

HollayHorvath avatar Jan 25 '21 12:01 HollayHorvath

Hi, nice idea. It appears there is a certain need for this, as the request for other containers comes up (in different flavors) from time to time:

  • https://github.com/rust-itertools/itertools/pull/276
  • https://github.com/rust-itertools/itertools/issues/322
  • https://github.com/rust-itertools/itertools/issues/462
  • https://github.com/rust-itertools/itertools/pull/515#discussion_r556991629
  • https://github.com/rust-itertools/itertools/issues/588

I'd like to put on the record (see https://github.com/rust-itertools/itertools/issues/462#issuecomment-659545723) that imho in an ideal world we would solve this problem by abstracting over the kind of the container -- leading to uniform support for HashMaps, BTreeMaps, sorted Vecs, EnumMap<Enum, Option<_>>, and possibly more, instead of having sporadic support for some of them.

It might not be easily doable, but I am unsure if duplicating functions here and there is better than exploring the possibilities of the aforementioned abstraction.

phimuemue avatar Jan 25 '21 14:01 phimuemue

Hey 👋🏻

Any updates on this?

loarca avatar Feb 09 '24 23:02 loarca

I did not see any update related to it. The only recent thing is me adding the label "generic-container". Personally, I tried some approaches to have more generic containers but nothing satisfying yet (by far).

Philippe-Cholet avatar Feb 10 '24 08:02 Philippe-Cholet