Giter VIP home page Giter VIP logo

eclectic's Issues

Redesign entry traits

The current design is nonsensical. With some future-Rust features, we could have:

pub trait EntryMap: Map {
    type Occupied<'a>: Occupied<'a = 'a, Key = Self::Key, Value = Self::Value>;
    type Vacant<'a>: Vacant<'a = 'a, Key = Self::Key, Value = Self::Value>;

    fn entry<'a>(&'a mut self, key: Self::Key)
        -> Entry<Self::Occupied<'a>, Self::Vacant<'a>>;
}

pub enum Entry<O, V>
where
    O: Occupied,
    V: Vacant<'a = O::'a, Key = O::Key, Value = O::Value>,
{
    Occupied(O),
    Vacant(V),
}

pub trait Occupied {
    lifetime 'a;
    type Key: Self::'a;
    type Value: Self::'a;

    fn into_mut(self) -> &Self::'a mut Self::Value;
    // ...
}

pub trait Vacant {
    lifetime 'a;
    type Key: Self::'a;
    type Value: Self::'a;

    fn insert(self, value: Self::Value) -> &Self::'a mut Self::Value;
    // ...
}

Consider supporting `VecMap` and `BitSet`

The former doesn't own its keys, and the latter doesn't own its items, but it probably requires higher-kinded types to be able to deal with these in the iteration methods.

Not clear that EntryMap can be used in generic contexts

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.

Determine `LinkedList`'s fate

Should it implement List? Should we add the following method (and/or a corresponding associated type or associated const) to List?

fn is_random_access(&self) -> bool;

Consider making `Collection::Item` `?Sized`

This would enable node-based collections to directly embed trait objects. For example:

struct Node<T: ?Sized> {
    left: Option<Box<Node<T>>>,
    right: Option<Box<Node<T>>>,
    item: T,
}

pub struct Heap<T: ?Sized> {
    root: Option<Box<Node<T>>>,
}

Add additional methods

  • Collection
    • capacity
    • into_vec
    • reserve_exact
    • with_capacity
  • List
    • reverse
    • sort
    • split_at(_mut)*
  • Set
    • {difference, intersection, symmetric_difference, union}*

*requires boxed trait objects or higher-kinded associated types

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.