pub fn group_by_key<T: Copy, U: Ord>(v: Vec<T>, key: impl Fn(&T)->U) -> Vec<Vec<T>> {
    let mut group = vec![v[0]];
    let mut groups = vec![];
    
    for i in 1..v.len() {
        // group zippers by their left sides being the same
        if key(&v[i]) == key(&v[i-1]) {
            // add on to old ztuplegroup
            group.push(v[i]);
        } else {
            // start a new ztuplegroup
            groups.push(group);
            group = vec![v[i]];
        }
    }
    groups.push(group);
    groups
}
/// Takes a SORTED vector of copyable items and a key function and groups adjacent equal-key items
/// into subvectors, returning the vector of these subvectors.
Takes a SORTED vector of copyable items and a key function and groups adjacent equal-key items
into subvectors, returning the vector of these subvectors.
Takes a SORTED vector of copyable items and a key function and groups adjacent equal - key items into subvectors returning the vector of these subvectors .
pub fn group_by_key<T: Copy, U: Ord>(v: Vec<T>, key: impl Fn(&T)->U) -> Vec<Vec<T>> {
    let mut group = vec![v[0]];
    let mut groups = vec![];
    for i in 1..v.len() {
        // group zippers by their left sides being the same
        if key(&v[i]) == key(&v[i-1]) {
            // add on to old ztuplegroup
            group.push(v[i]);
        } else {
            // start a new ztuplegroup
            groups.push(group);
            group = vec![v[i]];
        }
    }
    groups.push(group);
    groups
}
pub fn group_by_key < T : Copy , U : Ord > ( v : Vec < T > , key : impl Fn ( & T ) -> U ) -> Vec < Vec < T > > { let mut group = vec ! [ v [ 0 ] ] ; let mut groups = vec ! [ ] ; for i in 1 .. v . len ( ) { // group zippers by their left sides being the same if key ( & v [ i ] ) == key ( & v [ i - 1 ] ) { // add on to old ztuplegroup group . push ( v [ i ] ) ; } else { // start a new ztuplegroup groups . push ( group ) ; group = vec ! [ v [ i ] ] ; } } groups . push ( group ) ; groups }
Takes a SORTED vector of copyable items and a key function and groups adjacent equal-key items
into subvectors, returning the vector of these subvectors.
Takes a SORTED vector of copyable items and a key function and groups adjacent equal - key items into subvectors returning the vector of these subvectors .
v
Vec<T>
key
impl Fn(&T)->U
v
Vec<T>
key
impl Fn(&T)->U