FromIListMixin<T, I extends FromIListMixin<T, I>> mixin

This mixin implements all IList methods (without config (ConfigList)), plus operator [], but it does NOT implement Iterable nor IList.

It is meant to help you wrap an IList into another class (composition). You must override the iter getter to return the inner IList. All other methods are efficiently implemented in terms of the iter.

To use this mixin, your class must:

  1. Override the iter getter to return the inner IList.
  2. Override the newInstance method to return a new instance of the class.

Example:

class Students with FromIListMixin<Student, Students> {
  final IList<Student> _students;

  Students([Iterable<Student> students]) : _students = IList(students);

  @override
  Students newInstance(IList<Student> ilist) => Students(ilist);

  @override
  IList<Student> get iter => _students;
}

class Student implements Comparable<Student>{
  final String name;

  const Student(this.name);

  int compareTo(Student other) => name.compareTo(other.name);
}

Note: Why does this class NOT implement Iterable? Unfortunately, the expect method in tests compares Iterables by comparing its items. So if you create a class that implements Iterable and then, when you want to use the expect method, it will just compare its items, completely ignoring its operator ==.

If you need to iterate over this class, you can use the iter getter:

class MyClass with FromIListMixin<T, I> { ... }

MyClass obj = MyClass([1, 2, 3]);

for (int value in obj.iter) print(value);

Please note: if you really want to make your class Iterable, you can simply add the implements Iterable<T> to its declaration. For example:

class MyClass with FromIListMixin<T, I> implements Iterable<T> { ... }

MyClass obj = MyClass([1, 2, 3]);

for (int value in obj) print(value);

See also: FromIterableIListMixin.

Implemented types

Properties

first → T
no setter
firstOrNull → T?
no setter
hashCode int
The hash code for this object.
no setterinherited
isEmpty bool
no setteroverride
isNotEmpty bool
no setteroverride
iter IList<T>
Classes with FromIListMixin must override this.
no setter
iterator Iterator<T>
no setter
last → T
no setter
lastOrNull → T?
no setter
length int
no setter
reversed → I
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
single → T
no setter
singleOrNull → T?
no setter
unlock List<T>
no setter
unlockView List<T>
no setter

Methods

add(T item) → I
addAll(Iterable<T> items) → I
any(Predicate<T> test) bool
asMap() IMap<int, T>
cast<R>() Iterable<R>
clear() → I
contains(covariant T? element) bool
elementAt(int index) → T
equalItems(covariant Iterable<T> other) bool
every(Predicate<T> test) bool
expand<E>(Iterable<E> f(T)) Iterable<E>
fillRange(int start, int end, [T? fillValue]) → I
firstOr(T orElse) → T?
firstWhere(Predicate<T> test, {T orElse()?}) → T
firstWhereOrNull(Predicate<T> test) → T?
fold<E>(E initialValue, E combine(E previousValue, T element)) → E
followedBy(Iterable<T> other) Iterable<T>
forEach(void f(T element)) → void
getRange(int start, int end) Iterable<T>
indexOf(T element, [int start = 0]) int
indexWhere(Predicate<T> test, [int start = 0]) int
insert(int index, T element) → I
insertAll(int index, Iterable<T> iterable) → I
join([String separator = ""]) String
lastIndexOf(T element, [int? start]) int
lastIndexWhere(Predicate<T> test, [int? start]) int
lastOr(T orElse) → T
lastWhere(Predicate<T> test, {T orElse()?}) → T
map<E>(E f(T element)) Iterable<E>
maxLength(int maxLength, {int priority(T a, T b)?}) → I
newInstance(IList<T> ilist) → I
Classes with FromIListMixin must override this.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
process({bool test(IList<T> list, int index, T item)?, required Iterable<T> apply(IList<T> list, int index, T item)}) → I
put(int index, T value) → I
reduce(T combine(T value, T element)) → T
remove(T item) → I
removeAt(int index, [Output<T>? removedItem]) → I
removeLast([Output<T>? removedItem]) → I
removeRange(int start, int end) → I
removeWhere(Predicate<T> test) → I
replaceAll({required T from, required T to}) → I
replaceAllWhere(Predicate<T> test, T to) → I
replaceFirst({required T from, required T to}) → I
replaceFirstWhere(bool test(T item), T to) → I
replaceRange(int start, int end, Iterable<T> replacement) → I
retainWhere(Predicate<T> test) → I
same(I other) bool
setAll(int index, Iterable<T> iterable) → I
setRange(int start, int end, Iterable<T> iterable, [int skipCount = 0]) → I
shuffle([Random? random]) → I
singleOr(T orElse) → T
singleWhere(Predicate<T> test, {T orElse()?}) → T
skip(int count) Iterable<T>
skipWhile(bool test(T value)) Iterable<T>
sort([int compare(T a, T b)?]) → I
sublist(int start, [int? end]) → I
take(int count) Iterable<T>
takeWhile(bool test(T value)) Iterable<T>
toggle(T element) → I
toList({bool growable = true}) List<T>
toSet() Set<T>
toString() String
A string representation of this object.
override
unorderedEqualItems(covariant Iterable<T> other) bool
where(Predicate<T> test) Iterable<T>
whereType<E>() Iterable<E>

Operators

operator +(Iterable<T> other) → I
operator ==(Object other) bool
The equality operator.
inherited
operator [](int index) → T