castFrom<S, T> method

Set<T> castFrom <S, T>(Set<S> source, { Set<R> newSet() })
override

Adapts source to be a Set<T>.

If newSet is provided, it is used to create the new sets returned by toSet, union, and is also used for intersection and difference. If newSet is omitted, it defaults to creating a new set using the default Set constructor, and intersection and difference returns an adapted version of calling the same method on the source.

Any time the set would produce an element that is not a T, the element access will throw.

Any time a T value is attempted added into the adapted set, the store will throw unless the value is also an instance of S.

If all accessed elements of source are actually instances of T, and if all elements added to the returned set are actually instance of S, then the returned set can be used as a Set<T>.

Implementation

static Set<T> castFrom<S, T>(Set<S> source, {Set<R> Function<R>() newSet}) =>
    CastSet<S, T>(source, newSet);