toNonNullSet<T> function
Converts set
to a Set<T>
ignoring any null element.
forceTypeCast
: if true, will try to cast elements asT
. if false, will ignore any element that can't be cast.
Implementation
Set<T> toNonNullSet<T>(Set? set, {bool forceTypeCast = true}) {
if (set == null || set.isEmpty) {
return <T>{};
}
Set<T> set2;
if (forceTypeCast) {
set2 = set.where((e) => e != null).map((e) => e! as T).toSet();
} else {
set2 = set.whereType<T>().toSet();
}
return set2;
}