Skip to content
This repository was archived by the owner on Jun 4, 2025. It is now read-only.
This repository was archived by the owner on Jun 4, 2025. It is now read-only.

Not clear that EntryMap can be used in generic contexts #2

@Gankra

Description

@Gankra

I think it needs HKT or something loopy like that. For instance I tried implementing a super generic "categorize":

    extern crate eclectic;

    use eclectic::*;
    use std::hash::Hash;

    pub fn categorize<'a, D, B, F, O, M>(data: D, mut f: F) where
        D: IntoIterator + Sized,
        B: Default + Extend<D::Item> + 'static,
        F: FnMut(&D::Item) -> O,
        O: Hash + Eq,
        M: EntryMap<Key=O, Value=B> + Default,
    {
        let map = M::default();
        for x in data {
            match map.entry(f(&x)) {
                Entry::Vacant(v) => v.insert(B::default()),
                Entry::Occupied(o) => o.into_mut(),
            }.extend(Some(x));
        }
        map
    }

But it's not clear that a lifetime can be supplied for EntryMap.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions