StreamSet<E>.from constructor

StreamSet<E>.from(
  1. Iterable elements, {
  2. OnUpdate<Set<E>>? onUpdate,
  3. OnEvent<CollectionEvent<int, E>>? onEvent,
  4. OnChange<CollectionChangeEvent<int, E>>? onChange,
})

Creates a StreamSet that contains all elements.

All the elements should be instances of E. The elements iterable itself can have any type, so this constructor can be used to down-cast a Set, for example as:

Set<SuperType> superSet = ...;
Set<SubType> subSet =
    Set<SubType>.from(superSet.where((e) => e is SubType));

The created Set is a LinkedHashSet. As such, it considers elements that are equal (using operator ==) to be indistinguishable, and requires them to have a compatible Object.hashCode implementation.

The set is equivalent to one created by LinkedHashSet<E>.from(elements).

Implementation

factory StreamSet.from(
  Iterable elements, {
  OnUpdate<Set<E>>? onUpdate,
  OnEvent<CollectionEvent<int, E>>? onEvent,
  OnChange<CollectionChangeEvent<int, E>>? onChange,
}) {
  return StreamSet<E>(
    value: Set.from(elements),
    onUpdate: onUpdate,
    onEvent: onEvent,
    onChange: onChange,
  );
}