2014-09-19 16:38:37 -07:00
|
|
|
library facade.collection;
|
|
|
|
|
|
|
|
import 'dart:collection' show HashMap;
|
2014-10-02 20:39:27 -07:00
|
|
|
export 'dart:core' show Map, List, Set;
|
2014-09-19 16:38:37 -07:00
|
|
|
|
|
|
|
class MapWrapper {
|
|
|
|
static HashMap create() => new HashMap();
|
|
|
|
static get(m, k) => m[k];
|
|
|
|
static void set(m, k, v){ m[k] = v; }
|
|
|
|
static contains(m, k) => m.containsKey(k);
|
2014-09-30 14:56:33 -04:00
|
|
|
static forEach(m, fn) {
|
2014-10-18 17:50:55 -04:00
|
|
|
m.forEach((k,v) => fn(v,k));
|
2014-09-30 14:56:33 -04:00
|
|
|
}
|
2014-10-20 15:17:06 -04:00
|
|
|
static int size(m) {return m.length;}
|
2014-10-28 18:56:15 +01:00
|
|
|
static void delete(m, k) { m.remove(k); }
|
|
|
|
static void clear(m) { m.clear(); }
|
2014-09-19 16:38:37 -07:00
|
|
|
}
|
|
|
|
|
2014-10-28 14:46:38 -07:00
|
|
|
// TODO: how to export StringMap=Map as a type?
|
|
|
|
class StringMapWrapper {
|
|
|
|
static HashMap create() => new HashMap();
|
|
|
|
static get(map, key) {
|
|
|
|
return map[key];
|
|
|
|
}
|
|
|
|
static set(map, key, value) {
|
|
|
|
map[key] = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-19 16:38:37 -07:00
|
|
|
class ListWrapper {
|
|
|
|
static List clone(List l) => new List.from(l);
|
|
|
|
static List create() => new List();
|
2014-09-30 14:56:33 -04:00
|
|
|
static List createFixedSize(int size) => new List(size);
|
2014-09-19 16:38:37 -07:00
|
|
|
static get(m, k) => m[k];
|
|
|
|
static void set(m, k, v) { m[k] = v; }
|
2014-10-27 13:02:46 -04:00
|
|
|
static contains(List m, k) => m.contains(k);
|
2014-09-30 14:56:33 -04:00
|
|
|
static map(list, fn) => list.map(fn).toList();
|
2014-10-27 11:47:13 -04:00
|
|
|
static filter(List list, fn) => list.where(fn).toList();
|
2014-10-14 16:00:35 -04:00
|
|
|
static find(List list, fn) => list.firstWhere(fn, orElse:() => null);
|
|
|
|
static any(List list, fn) => list.any(fn);
|
2014-09-30 14:56:33 -04:00
|
|
|
static forEach(list, fn) {
|
|
|
|
list.forEach(fn);
|
|
|
|
}
|
2014-10-28 12:22:38 -04:00
|
|
|
static reduce(List list, Function fn, init) {
|
|
|
|
return list.fold(init, fn);
|
|
|
|
}
|
2014-10-07 10:42:27 -04:00
|
|
|
static first(List list) => list.first;
|
|
|
|
static last(List list) => list.last;
|
|
|
|
static List reversed(List list) => list.reversed.toList();
|
2014-09-26 13:52:12 -07:00
|
|
|
static void push(List l, e) { l.add(e); }
|
2014-11-04 10:19:37 -08:00
|
|
|
static List concat(List a, List b) {a.addAll(b); return a;}
|
2014-10-28 18:56:15 +01:00
|
|
|
static bool isList(l) => l is List;
|
|
|
|
static void insert(List l, int index, value) { l.insert(index, value); }
|
|
|
|
static void removeAt(List l, int index) { l.removeAt(index); }
|
|
|
|
static void clear(List l) { l.clear(); }
|
2014-09-26 13:52:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
class SetWrapper {
|
|
|
|
static Set createFromList(List l) { return new Set.from(l); }
|
|
|
|
static bool has(Set s, key) { return s.contains(key); }
|
2014-09-19 16:38:37 -07:00
|
|
|
}
|