<commit_before>#![cfg(feature = "use_std")]

use std::collections::HashMap;
use std::hash::Hash;
use std::iter::Iterator;

/// Return a `HashMap` of keys mapped to a list of their corresponding values.
///
/// See [`.into_group_map()`](../trait.Itertools.html#method.into_group_map)
/// for more information.
pub fn into_group_map<I, K, V>(iter: I) -> HashMap<K, Vec<V>>
    where I: Iterator<Item=(K, V)>,
          K: Hash + Eq,
{
    let mut lookup = HashMap::new();

    for (key, val) in iter {
        lookup.entry(key).or_insert(Vec::new()).push(val);
    }

    lookup
}<commit_msg>Added into_group_map_by, into_group_map_by_fold<commit_after>#![cfg(feature = "use_std")]

use std::collections::HashMap;
use std::hash::Hash;
use std::iter::Iterator;

/// Return a `HashMap` of keys mapped to a list of their corresponding values.
///
/// See [`.into_group_map()`](../trait.Itertools.html#method.into_group_map)
/// for more information.
pub fn into_group_map<I, K, V>(iter: I) -> HashMap<K, Vec<V>>
    where I: Iterator<Item=(K, V)>,
          K: Hash + Eq,
{
    let mut lookup = HashMap::new();

    for (key, val) in iter {
        lookup.entry(key).or_insert(Vec::new()).push(val);
    }

    lookup
}

pub fn into_group_map_by<I, K, V>(iter: I, f: impl Fn(&V) -> K) -> HashMap<K, Vec<V>>
    where I: Iterator<Item=V>,
          K: Hash + Eq,
{
    let mut lookup = HashMap::new();

    for val in iter {
        let key = f(&val);
        lookup.entry(key).or_insert(Vec::new()).push(val);
    }

    lookup
}

pub fn into_group_map_by_fold<I, K, V, Acc, Fold>(iter: I, f_key: impl Fn(&V) -> K,
                                             init: Acc,
                                             fold: Fold) -> HashMap<K, Acc>
    where I: Iterator<Item=V>,
          K: Hash + Eq,
          Acc: Clone,
          Fold : FnMut(Acc,V) -> Acc + Clone


{
    let mut lookup = HashMap::new();

    for val in iter {
        let key = f_key(&val);
        lookup.entry(key).or_insert(Vec::new()).push(val);
    }

    lookup
        .into_iter()
        .map(move |(key,value)| (key, value.into_iter().fold(init.clone(), fold.clone())))
        .collect()
}


{'fraction_non_alphanumeric': 0.17603686635944701, 'fraction_numerical': 0.0, 'mean_word_length': 2.507269789983845, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7102589', 'n_tokens_mistral': 761, 'n_tokens_neox': 751, 'n_words': 187}