slice-group-by icon indicating copy to clipboard operation
slice-group-by copied to clipboard

LinearGroupByKey could allow provided closure to borrow from input

Open Ten0 opened this issue 2 years ago • 2 comments
trafficstars

Current:

fn linear_group_by_key<F, K>(&self, func: F) -> LinearGroupByKey<T, F>
    where F: FnMut(&T) -> K,
          K: PartialEq

Does not allow:

let strings = vec!["A".to_owned()];
strings.linear_group_by_key(|s| s.as_str());

In order for that to work, we need:

fn linear_group_by_key<'a, F, K>(&'a self, func: F) -> LinearGroupByKey<T, F>
    where F: FnMut(&'a T) -> K,
          K: PartialEq

Since nothing moves in memory it should be possible.

Ten0 avatar Aug 16 '23 15:08 Ten0

Hey @Ten0 👋

That's a great idea, and it is not breaking. Can you please propose a pull request and even copy/paste your comment into this official thread, too?

Kerollmops avatar Dec 14 '23 13:12 Kerollmops