Eigenpoll : D wish list : Finite sets 

I often end up using an array when I only intended to represent a set, which is wasteful since sets are a more primitive object. Moreover, they are complementary to associative arrays and can share some of the same underlying infrastructure.

Some ideas:

T{} v;
T{} w; // sets of objects of type T

T x;

// operations
v \ w; // difference
v & w; // intersection
v | w; // union

v * w; // cartesian product (if we had pairs)
v + w; // tagged union

x in v; // membership

v < w; // subset (not necessarily proper)
v > w; // superset
v == w; // equality


// casting
T[] a = cast(T[]) v; // arbitrary order
T{} v = cast(T{}) a;

T{} u = cast(T{}) x; // create a singleton set

// iteration
foreach(T x; v){...}

Note: {}'s may be an infeasible choice of syntax, this is probably more obvious to someone else.


Report this item for cleanup