ISet<T> class abstract

An immutable, ordered set. It can be configured to order by insertion order, or sort.

You can access its items by index, as efficiently as with a List, by calling ISet.elementAt(index) or by using the [] operator.

Inheritance
Implemented types
Implementers
Available extensions
Annotations
  • @immutable

Constructors

ISet([Iterable<T>? iterable])
Create an ISet from an iterable, with the default configuration. Fast, if the iterable is another ISet.
factory
ISet.empty()
Create an empty ISet. Use it with const: const ISet.empty() (It's always an ISetEmpty).
const
factory
ISet.fromJson(dynamic json, T fromJsonT(Object?))
Converts from JSon. Json serialization support for json_serializable with @JsonSerializable.
factory
ISet.unsafe(Set<T> set, {required ConfigSet config})
Unsafe constructor. Use this at your own peril.
factory
ISet.withConfig(Iterable<T>? iterable, ConfigSet config)
Create an ISet from any Iterable and a ConfigSet. Fast, if the Iterable is another ISet. If iterable is null, return an empty ISet.
factory

Properties

anyItem → T
Returns any item from the set. This is useful if you need to read some property that you know all items in the set have.
no setter
asComparableEntries Iterable<Entry<K, V>>

Available on Iterable<MapEntry<K, V>>, provided by the FicIterableOfMapEntryExtension extension

MapEntry is not Comparable. If you need to compare two iterables of MapEntry you can do this:
no setter
config ConfigSet
The set configuration.
no setter
first → T
  • If the set's config has ConfigSet.sort true, will return the first element in the natural order of items. Note: This is not a fast operation, as ISets are not naturally sorted.
  • If the set's config has ConfigSet.sort false (the default), or if the items are not Comparable, the first item by insertion will be returned.
  • no setteroverride
    firstOrNull → T?
    Returns the first element, or null if the set is empty.
    no setter
    firstOrNull → T?

    Available on Iterable<T>, provided by the IterableExtensions extension

    The first element of this iterator, or null if the iterable is empty.
    no setter
    flush ISet<T>
    Flushes the set, if necessary. Chainable method. If the set is already flushed, don't do anything.
    no setteroverride
    hashCode int
    The hash code for this object.
    no setteroverride
    indexed Iterable<(int, T)>

    Available on Iterable<T>, provided by the IterableExtensions extension

    Pairs of elements of the indices and elements of this iterable.
    no setter
    isDeepEquals bool
    See also: ConfigList
    no setter
    isEmpty bool
    Returns true if there are no elements in this collection.
    no setteroverride
    isFlushed bool
    Whether this set is already flushed or not.
    no setteroverride
    isIdentityEquals bool
    See also: ConfigList
    no setter
    isNotEmpty bool
    Returns true if there is at least one element in this collection.
    no setteroverride
    iterator Iterator<T>
  • If the set's config has ConfigSet.sort true, it will iterate in the natural order of items. In other words, if the items are Comparable, they will be sorted by a.compareTo(b).
  • If the set's config has ConfigSet.sort false (the default), or if the items are not Comparable, the iterator order is the insertion order.
  • no setteroverride
    last → T
  • If the set's config has ConfigSet.sort true, will return the last element in the natural order of items. Note: This is not a fast operation, as ISets are not naturally sorted.
  • If the set's config has ConfigSet.sort false (the default), or if the items are not Comparable, the last item by insertion will be returned.
  • no setteroverride
    lastOrNull → T?
    Returns the last element, or null if the set is empty.
    no setter
    lastOrNull → T?

    Available on Iterable<T>, provided by the IterableExtensions extension

    The last element of this iterable, or null if the iterable is empty.
    no setter
    length int
    The number of objects in this set.
    no setteroverride
    nonNulls Iterable<T>

    Available on Iterable<T?>, provided by the NullableIterableExtensions extension

    The non-null elements of this iterable.
    no setter
    runtimeType Type
    A representation of the runtime type of the object.
    no setterinherited
    single → T
    Checks that this iterable has only one element, and returns that element. Throws a StateError if the set is empty or has more than one element.
    no setteroverride
    singleOrNull → T?
    Checks that the set has only one element, and returns that element. Return null if the set is empty or has more than one element.
    no setter
    singleOrNull → T?

    Available on Iterable<T>, provided by the IterableExtensions extension

    The single element of this iterator, or null.
    no setter
    unlock Set<T>
    Unlocks the set, returning a regular (mutable, ordered) Set of type LinkedHashSet. This set is "safe", in the sense that is independent from the original ISet.
    no setter
    unlockLazy Set<T>
    Unlocks the set, returning a safe, modifiable (mutable) Set. Using this is very fast at first, since it makes no copies of the ISet items. However, if and only if you use a method that mutates the set, like add, it will unlock internally (make a copy of all ISet items). This is transparent to you, and will happen at most only once. In other words, it will unlock the ISet, lazily, only if necessary. If you never mutate the set, it will be very fast to lock this set back into an ISet.
    no setter
    unlockView Set<T>
    Unlocks the set, returning a safe, unmodifiable (immutable) Set view. The word "view" means the set is backed by the original ISet. Using this is very fast, since it makes no copies of the ISet items. However, if you try to use methods that modify the set, like add, it will throw an UnsupportedError. It is also very fast to lock this set back into an ISet.
    no setter
    wait Future<List<T>>

    Available on Iterable<Future<T>>, provided by the FutureIterable extension

    Waits for futures in parallel.
    no setter
    withDeepEquals ISet<T>
    Creates a set with deepEquals (compares all set items by equality).
    no setter
    withIdentityEquals ISet<T>
    Creates a set with identityEquals (compares the internals by identity).
    no setter

    Methods

    add(T item) ISet<T>
    Returns a new set containing the current set plus the given item.
    addAll(Iterable<T>? items) ISet<T>
    Returns a new set containing the current set plus all the given items.
    any(Predicate<T> test) bool
    Checks whether any element of this iterable satisfies test.
    override
    anyIs(T value) bool

    Available on Iterable<T>, provided by the FicIterableExtension extension

    Returns true if any item is equal to value.
    asList() List<T>

    Available on Iterable<T>, provided by the FicIterableExtension extension

    Returns a List containing the elements of this iterable. If the Iterable is already a List, return the same instance (nothing new is created). Otherwise, create a new List from it. See also: Dart's native toList, which always creates a new list.
    asNameMap() Map<String, T>

    Available on Iterable<T>, provided by the EnumByName extension

    Creates a map from the names of enum values to the values.
    asSet() Set<T>

    Available on Iterable<T>, provided by the FicIterableExtension extension

    Creates a Set containing the same elements as this iterable. If the Iterable is already a Set, return the same instance (nothing new is created). Otherwise, create a new Set from it. See also: Dart's native toSet, which always creates a new set.
    averageBy<N extends num>(N mapper(T element)) double

    Available on Iterable<T>, provided by the FicIterableExtension extension

    The arithmetic mean of the elements of a non-empty iterable. The arithmetic mean is the sum of the elements divided by the number of elements. If iterable is empty it returns 0. Examples:
    byName(String name) → T

    Available on Iterable<T>, provided by the EnumByName extension

    Finds the enum value in this list with name name.
    cast<R>() Iterable<R>
    Returns an iterable of R instances. If this set contains instances which cannot be cast to R, it will throw an error.
    override
    clear() ISet<T>
    Returns an empty set with the same configuration.
    contains(covariant T? element) bool
    Returns true if the collection contains an element equal to element, false otherwise.
    override
    containsAll(Iterable<T> other) bool
    Returns whether this ISet contains all the elements of other.
    deepEquals(Iterable? other, {bool ignoreOrder = false}) bool

    Available on Iterable<T>, provided by the FicIterableExtension extension

    Compare all items, in order or not, according to ignoreOrder, using operator ==. Return true if they are all the same, in the same order.
    deepEqualsByIdentity(Iterable? other, {bool ignoreOrder = false}) bool

    Available on Iterable<T>, provided by the FicIterableExtension extension

    Return true if they are all the same, in the same order. Compare all items, in order or not, according to ignoreOrder, using identical. Return true if they are all the same, in the same order.
    difference(Iterable<T> other) ISet<T>
    Returns a new set with the elements of this that are not in other.
    elementAt(int index) → T
    Returns the indexth element.
    override
    elementAtOrNull(int index) → T?

    Available on Iterable<T>, provided by the IterableExtensions extension

    The element at position index of this iterable, or null.
    equalItems(covariant Iterable? other) bool
    Will return true only if the ISet has the same number of items as the iterable, and the ISet items are equal to the iterable items, in whatever order. This may be slow for very large sets, since it compares each item, one by one.
    override
    equalItemsAndConfig(ISet? other) bool
    Will return true only if the set items are equal and the set configurations are equal. This may be slow for very large sets, since it compares each item, one by one.
    override
    every(Predicate<T> test) bool
    Checks whether every element of this iterable satisfies test.
    override
    everyIs(T value) bool

    Available on Iterable<T>, provided by the FicIterableExtension extension

    Returns true if all items are equal to value.
    expand<E>(Iterable<E> f(T), {ConfigSet? config}) Iterable<E>
    Expands each element of this ISet into zero or more elements.
    override
    findDuplicates() Set<T>

    Available on Iterable<T>, provided by the FicIterableExtension extension

    Finds duplicates and then returns a Set with the duplicated elements. If there are no duplicates, an empty Set is returned.
    firstOr(T orElse) → T
    Returns the first element, or orElse if the set is empty.
    firstWhere(Predicate<T> test, {T orElse()?}) → T
    Iterates through elements and returns the first to satisfy test.
    override
    fold<E>(E initialValue, E combine(E previousValue, T element)) → E
    Reduces a collection to a single value by iteratively combining eac element of the collection with an existing value.
    override
    followedBy(Iterable<T> other) Iterable<T>
    Returns the lazy concatenation of this iterable and other.
    override
    forEach(void f(T element)) → void
    Applies the function f to each element of this collection in iteration order.
    override
    intersection(Iterable<T> other) ISet<T>
    Returns a new set which is the intersection between this set and other.
    intersectsWith(Iterable<T> other) bool

    Available on Iterable<T>, provided by the FicIterableExtension extension

    Returns true if this Iterable has any items in common with the other Iterable. This method is as performant as possible, but it will be faster if any of the Iterables is a Set or an ISet.
    isFirst(T item) bool

    Available on Iterable<T>, provided by the FicIterableExtension extension

    Return true if the given item is the same (by identity) as the first iterable item. If this iterable is empty, always return null. This is useful for non-indexed loops where you need to know when you have the first item. For example:
    isLast(T item) bool

    Available on Iterable<T>, provided by the FicIterableExtension extension

    Return true if the given item is the same (by identity) as the last iterable item. If this iterable is empty, always return null. This is useful for non-indexed loops where you need to know when you have the last item. For example:
    isNotFirst(T item) bool

    Available on Iterable<T>, provided by the FicIterableExtension extension

    Return true if the given item is NOT the same (by identity) as the first iterable item. If this iterable is empty, always return null. This is useful for non-indexed loops where you need to know when you don't have the first item. For example:
    isNotLast(T item) bool

    Available on Iterable<T>, provided by the FicIterableExtension extension

    Return true if the given item is NOT the same (by identity) as the last iterable item. If this iterable is empty, always return null. This is useful for non-indexed loops where you need to know when you don't have the last item. For example:
    join([String separator = ""]) String
    Converts each element to a String and concatenates the strings with the separator in-between each concatenation.
    override
    lastOr(T orElse) → T
    Returns the last element, or orElse if the set is empty.
    lastWhere(Predicate<T> test, {T orElse()?}) → T
    Returns the last element that satisfies the given predicate test.
    override
    lengthCompare(Iterable others) bool
    Compare with others length
    lookup(T element) → T?
    If an object equal to object is in the set, return it.
    map<E>(E f(T element), {ConfigSet? config}) Iterable<E>
    Returns an Iterable with elements that are created by calling f on each element of this ISet in iteration order.
    override
    mapIndexedAndLast<R>(R convert(int index, T item, bool isLast)) Iterable<R>

    Available on Iterable<T>, provided by the FicIterableExtension extension

    Maps each element and its index to a new value. This is similar to mapIndexed but also tells you which item is the last.
    mapNotNull<E>(E? f(T? e)) Iterable<E>

    Available on Iterable<T?>, provided by the FicIterableExtensionTypeNullable extension

    Similar to map, but MAY return a non-nullable type.
    noSuchMethod(Invocation invocation) → dynamic
    Invoked when a nonexistent method or property is accessed.
    inherited
    reduce(T combine(T value, T element)) → T
    Reduces a collection to a single value by iteratively combining elements of the collection using the provided function.
    override
    remove(T item) ISet<T>
    Returns a new set containing the current set minus the given item. However, if the given item didn't exist in the current set, it will return the current set (same instance).
    removeAll(Iterable<Object?> elements) ISet<T>
    Removes each element of elements from this set.
    removeWhere(Predicate<T> test) ISet<T>
    Removes all elements of this set that satisfy test.
    restrict(T? item, {required T orElse}) → T

    Available on Iterable<T>, provided by the FicIterableExtension extension

    Restricts some item to one of those present in this iterable.
    retainAll(Iterable<Object?> elements) ISet<T>
    Removes all elements of this set that are not elements in elements.
    retainWhere(Predicate<T> test) ISet<T>
    Removes all elements of this set that fail to satisfy test.
    same(ISet<T>? other) bool
    Will return true if the sets internals are the same instances (comparing by identity). This will be fast even for very large sets, since it doesn't compare each item.
    override
    singleOr(T orElse) → T
    Checks if the set has only one element, and returns that element. Return null if the set is empty or has more than one element.
    singleWhere(Predicate<T> test, {T orElse()?}) → T
    Returns the single element that satisfies test.
    override
    skip(int count) Iterable<T>
    Returns an ISet that provides all but the first count elements.
    override
    skipWhile(bool test(T value)) Iterable<T>
    Returns an ISet that skips leading elements while test is satisfied.
    override
    sortedLike(Iterable ordering) List<T>

    Available on Iterable<T>, provided by the FicIterableExtension extension

    Returns a list, sorted according to the order specified by the ordering iterable. Items which don't appear in ordering will be included in the end, in their original order. Items of ordering which are not found in the original list are ignored.
    sortedReversed([Comparator<T>? compare]) List<T>

    Available on Iterable<T>, provided by the FicIterableExtension extension

    Creates a reversed sorted list of the elements of the iterable.
    sumBy<N extends num>(N mapper(T element)) → N

    Available on Iterable<T>, provided by the FicIterableExtension extension

    The sum of the values returned by the mapper function.
    take(int count) Iterable<T>
    Returns an ISet of the count first elements of this iterable.
    override
    takeWhile(bool test(T value)) Iterable<T>
    Returns an ISet of the leading elements satisfying test.
    override
    toggle(T item) ISet<T>
    Removes the element, if it exists in the set. Otherwise, adds it to the set.
    toIList({int compare(T a, T b)?, ConfigList? config}) IList<T>
    Returns a IList with all items from the set.
    toIList([ConfigList? config]) IList<T>

    Available on Iterable<T>, provided by the FicIterableExtension extension

    Creates an immutable list (IList) from the iterable.
    toISet([ConfigSet? config]) ISet<T>

    Available on Iterable<T>, provided by the FicIterableExtension extension

    Creates an immutable set (ISet) from the iterable.
    toJson(Object? toJsonT(T)) Object
    Converts to JSon. Json serialization support for json_serializable with @JsonSerializable.
    toList({bool growable = true, int compare(T a, T b)?}) List<T>
    Returns a List with all items from the set.
    override
    toSet({int compare(T a, T b)?}) Set<T>
    Returns a Set with all items from the ISet.
    override
    toString([bool? prettyPrint]) String
    Returns a string representation of (some of) the elements of this.
    override
    union(Iterable<T> other) ISet<T>
    Returns a new set which contains all the elements of this set and other.
    unorderedEqualItems(covariant Iterable? other) bool
    Will return true only if the ISet and the iterable items have the same number of elements, and the elements of the ISet can be paired with the elements of the iterable, so that each pair is equal. This may be slow for very large sets, since it compares each item, one by one.
    unzip() → (Iterable<U>, Iterable<V>)

    Available on Iterable<(U, V)>, provided by the FICZipExtension extension

    Iterable Record as Iterable
    updateById(Iterable<T> newItems, dynamic id(T item)) List<T>

    Available on Iterable<T>, provided by the FicIterableExtension extension

    Returns a new list where newItems are added or updated, by their id (and the id is a function of the item), like so:
    where(Predicate<T> test) Iterable<T>
    Returns an ISet with all elements that satisfy the predicate test.
    override
    whereNoDuplicates({dynamic by(T item)?, bool removeNulls = false}) Iterable<T>

    Available on Iterable<T>, provided by the FicIterableExtension extension

    Removes all duplicates, leaving only the distinct items. Optionally, you can provide an by function to compare the items.
    whereType<E>() Iterable<E>
    Returns an ISet with all elements that have type E.
    override
    withConfig(ConfigSet config) ISet<T>
    Creates a new set with the given config.
    withConfigFrom(ISet<T> other) ISet<T>
    Returns a new set with the contents of the present ISet, but the config of other.

    Operators

    operator +(Iterable<T> other) ISet<T>
    Returns the concatenation of this set and other. Returns a new set containing the elements of this set followed by the elements of other.
    operator ==(Object other) bool
  • If isDeepEquals configuration is true: Will return true only if the set items are equal (and in the same order), and the set configurations are equal. This may be slow for very large sets, since it compares each item, one by one.

  • If isDeepEquals configuration is false: Will return true only if the sets internals are the same instances (comparing by identity). This will be fast even for very large sets, since it doesn't compare each item.

  • override
    operator [](int index) → T
    Returns the indexth element.

    Static Properties

    defaultConfig ConfigSet
    Global configuration that specifies if, by default, the ISets use equality or identity for their operator ==.
    getter/setter pair
    flushFactor int
    Indicates the number of operations an ISet may perform before it is eligible for auto-flush. Must be larger than 0.
    getter/setter pair

    Static Methods

    fromIterable<T, I>(Iterable<I> iterable, {required Iterable<T>? mapper(I), ConfigSet? config}) ISet<T>
    Creates a set in which the items are computed from the iterable.
    orNull<T>(Iterable<T>? iterable, [ConfigSet? config]) ISet<T>?
    If Iterable is null, return null.
    resetAllConfigurations() → void
    See also: ImmutableCollection, ImmutableCollection.lockConfig, ImmutableCollection.isConfigLocked,flushFactor, defaultConfig
    override