query<C extends T> method

Iterable<C> query<C extends T>()

Allow you to find a subset of this set with all the elements e for which the condition e is C is true. This is equivalent to

  orderedSet.whereType<C>()

except that it is O(0).

Note: you must call register for every type C you desire to use before calling this, or set strictMode to false.

Implementation

Iterable<C> query<C extends T>() {
  final result = _cache[C];
  if (result == null) {
    if (strictMode) {
      throw 'Cannot query unregistered query $C';
    } else {
      register<C>();
      return query<C>();
    }
  }
  // We are returning the cached List itself but we cast it as an Iterable
  // to prevent users from accidentally modifying the cache from outside.
  // We are not using an UnmodifiableListView() or anything similar because
  // we want to avoid creating a new object for every query.
  return result.data as Iterable<C>;
}