fast_immutable_collections library Collections, Immutable, Flutter

Data objects for working with immutable collections in Dart and Flutter. Developed by Marcelo Glasberg (2021) https://glasberg.dev and https://github.com/marcglasberg For more info, see: https://pub.dartlang.org/packages/fast_immutable_collections

Classes

CanBeEmpty
Your own classes can implement this so they may use CanBeEmptyExtension.
ConfigList
  • If isDeepEquals is false, the IList equals operator (==) compares by identity.
  • If isDeepEquals is true (the default), the IList equals operator (==) compares all items, ordered.
  • If cacheHashCode is true (the default), the IList will only calculate the hashCode once, when it is asked — initially, internally null. Otherwise, it will always recalculate it.
  • ConfigMap
  • If isDeepEquals is false, the IMap equals operator (==) compares by identity.
  • If isDeepEquals is true (the default), the IMap equals operator (==) compares all entries, ordered.
  • If sort is true, will sort the list output of keys. Otherwise, it will keep the insertion order (the default).
  • If cacheHashCode is true (the default), the IMap will only calculate the hashCode once, when it is asked — initially, internally null. Otherwise, it will always recalculate it.
  • ConfigMapOfSets
  • If isDeepEquals is false, the IMap equals operator (==) compares by identity.
  • If isDeepEquals is true (the default), the IMap equals operator (==) compares all entries, ordered.
  • If sortKeys is true, will sort the list output of keys. Otherwise, it will keep the insertion order (the default).
  • If cacheHashCode is true (the default), the IMapOfSets will only calculate the hashCode once, when it is asked — initially, internally null. Otherwise, it will always recalculate it.
  • ConfigSet
    The set configuration.
    DiffAndIntersectResult<T, G>
    Entry<K, V>
    Similar to a MapEntry, but correctly implements equals (== comparing key and value), hashcode and Comparable.compareTo.
    IList<T>
    An immutable list. Note: The replace method is the equivalent of operator []= for the IList.
    IListConst<T>
    This is an IList which can be made constant. Note: Don't ever use it without the "const" keyword, because it will be unsafe.
    IListEmpty<T>
    This is an IList which is always empty.
    IListOf2<T>
    An immutable list of only 2 items.
    IListOf3<T>
    An immutable list of only 3 items.
    IListOf4<T>
    An immutable list of only 4 items.
    IMap<K, V>
    An immutable, unordered map.
    IMapConst<K, V>
    This is an IMap which can be made constant. Note: Don't ever use it without the "const" keyword, because it will be unsafe.
    IMapEmpty<K, V>
    This is an IMap which is always empty.
    IMapOfSets<K, V>
    An immutable, unordered, map of sets.
    IMapOfSetsConst<K, V>
    ImmutableCollection<C>
    ISet<T>
    An immutable, ordered set. It can be configured to order by insertion order, or sort.
    ISetConst<T>
    This is an ISet which can be made constant. Note: Don't ever use it without the "const" keyword, because it will be unsafe.
    ISetEmpty<T>
    This is an ISet which is always empty.
    ListMap<K, V>
    A ListMap is a mutable, fixed-sized, and ordered map.
    ListMapView<K, V>
    A ListMapView lets you view a regular map as if it was a ListMap. At the moment this class is for FIC's internal use only, since a lot of its methods will throw UnsupportedError.
    ListSet<T>
    A ListSet is, at the same time:
    ListSetView<T>
    MapEntryEquality<E>
    This works for any object, not only map entries, but MapEntry gets special treatment. We consider two map-entries equal when their respective key and values are equal.
    ModifiableListFromIList<T>
    The ModifiableListFromIList is a safe, modifiable List that is built from an IList. The construction of the list is fast at first, since it makes no copies of the IList items, but just uses it directly.
    ModifiableMapFromIMap<K, V>
    The ModifiableMapFromIMap is a safe, modifiable Map that is built from an IMap. The construction of the map is fast at first, since it makes no copies of the IMap items, but just uses it directly.
    ModifiableSetFromISet<T>
    The ModifiableSetFromISet is a safe, modifiable Set that is built from an ISet. The construction of the set is fast at first, since it makes no copies of the ISet items, but just uses it directly.
    Output<T>
    Meant to be used when you wish to save a value that's going to be tossed out of an immutable collection.
    ReversedListView<T>
    Returns a List of the objects in this list in reverse order. Very efficient since it returns a view, which means if you change the original list this one will also change, and vice-versa.
    UnmodifiableListFromIList<T>
    The UnmodifiableListFromIList is a relatively safe, unmodifiable List view that is built from an IList or another List. The construction of the UnmodifiableListFromIList is very fast, since it makes no copies of the given list items, but just uses it directly.
    UnmodifiableMapFromIMap<K, V>
    The UnmodifiableMapFromIMap is a relatively safe, unmodifiable Map that is built from an IMap or another Map. The construction of the UnmodifiableMapFromIMap is very fast, since it makes no copies of the given map items, but just uses it directly.
    UnmodifiableSetFromISet<T>
    The UnmodifiableSetFromISet is a relatively safe, unmodifiable Set view that is built from an ISet or another Set. The construction of the UnmodifiableSetFromISet is very fast, since it makes no copies of the given set items, but just uses it directly.

    Mixins

    FromIListMixin<T, I extends FromIListMixin<T, I>>
    This mixin implements all IList methods (without config (ConfigList)), plus operator [], but it does NOT implement Iterable nor IList.
    FromISetMixin<T, I extends FromISetMixin<T, I>>
    This mixin implements all ISet members (without config), but it does NOT implement Iterable nor ISet.
    FromIterableIListMixin<T>
    This mixin implements all Iterable methods, plus operator [], but it does NOT implement Iterable nor IList.
    FromIterableISetMixin<T>
    This mixin implements all Iterable methods, but it does NOT implement Iterable nor ISet.

    Functions

    areImmutableCollectionsWithEqualItems(ImmutableCollection? c1, ImmutableCollection? c2) bool
    Will return true only if the collections are of the same type, and their items are equal by calling the collection's equalItems method. This may be slow for very large collection, since it compares each item, one by one. Note this will not compare the collection configuration.
    areSameImmutableCollection(ImmutableCollection? c1, ImmutableCollection? c2) bool
    While identical(collection1, collection2) will compare the collections by identity, areSameImmutableCollection(collection1, collection2) will compare them by type, and then by their internal state. Note this is practically as fast as identical, but will give less false negatives. So it is almost always recommended to use areSameImmutableCollection instead of identical.
    combineIterables<A, B, R>(Iterable<A> a, Iterable<B> b, R combine(A, B), {bool allowDifferentSizes = false}) Iterable<R>
    Combines iterables a and b into one, by applying the combine function. If allowDifferentSizes is true, it will stop as soon as one of the iterables has no more values. If allowDifferentSizes is false, it will throw an error if the iterables have different length.
    compareObject<T extends Object>(Object? a, Object? b, {bool nullsBefore = false}) int
    The compareObject comparator is similar to the natural comparator provided by Comparable objects in their Comparable.compareTo method, to sort objects in their "natural order". The difference here is that compareObject is also able to compare some objects which are not Comparable, such as bool, MapEntry, Enum, and nulls.
    sortBy<T>(Predicate<T> test, {int then(T, T)?}) int Function(T, T)
    The sortBy function can be used to create a comparator to sort collections, comparing a and b such that:
    sortLike<T, E>(Iterable<E> order, {E mapper(T)?, int then(T, T)?}) int Function(T, T)
    The sortLike function can be used to create a comparator to sort collections, comparing a and b such that:

    Typedefs

    EQ<T, U> = bool Function(T item, U other)
    Op<T> = T Function(T element)
    Operation of type that conserve the original type
    Predicate<T> = bool Function(T element)