2 ms·
You've clearly put a massive amount of work into this API, which I applaud. One trick I use in FSet that you might want to copy is default values for maps. Th
by ScottBurson 12y ago
You've clearly put a massive amount of work into this API, which I applaud.
One trick I use in FSet that you might want to copy is default values for maps. This is particularly handy when the range type of the map is another collection: you can make the default value be the appropriate kind of empty collection, making it unnecessary for code that accesses the map to check for a null value. In Java, for example:
FMap<Foo, FSet<Bar>> m = new FHashMap.withDefault(FHashSet.emptyMap());
// now I can do:
for (Bar b : m.get(x)) ...
// without worrying about whether 'm' contains an entry for 'x'.
- leebyron 12y agoGreat feature. Immutable.js supports something similar but at the access site: var m: Im.Map<string, Im.Set<string>> = Im.Map(); console.log(m.get('foo')); // maybe undefined console.log(m.get('foo', Im.Set())); // never undefined typescript (and soon, flow) checks that the second arg to .get() is a Value type. Flow has the concept of non-nullable types, which will eventually let us type the return value of `get(key: K): V?` differently from `get(key: K, otherwise: V): V`