LogoSignals.dart
Copy Markdown
rodydavis/signals.dart 999999

IterableSignalMixin

A mixin that adds reactive <code>Iterable</code> methods and properties to a Signal.

A mixin that adds reactive Iterable methods and properties to a Signal holding an Iterable value.

This mixin delegates all standard Iterable operations (such as length, first, last, map, where, and any) directly to the underlying collection, while ensuring that any read operations register a reactive dependency on the signal.

This mixin only works with signals that have a value type extending Iterable.

Example Usage#

import 'package:signals/signals.dart';

class MyIterableSignal extends Signal<Iterable<int>>
    with IterableSignalMixin<int, Iterable<int>> {
  MyIterableSignal(super.internalValue);
}

void main() {
  final numbers = MyIterableSignal([1, 2, 3]);

  // Set up a reactive effect that prints the list size and first element
  effect(() {
    print('Size: ${numbers.length}, First: ${numbers.first}');
  }); // Prints: "Size: 3, First: 1"

  // Update the signal value (triggers the effect)
  numbers.value = [10, 20, 30, 40]; // Prints: "Size: 4, First: 10"
}
Direct mutation of elements inside the iterable will NOT notify listeners unless you reassign the value or use a specialized signal class like ListSignal, SetSignal, or MapSignal which automatically trigger updates when modified.

Methods#

View Methods
bool any(bool Function(E element) test)
Iterable cast()
bool contains(Object? value)
E elementAt(int index)
bool every(bool Function(E element) test)
Iterable expand(Iterable Function(E element) toElements)
E first
E firstWhere(bool Function(E element) test, {E Function()? orElse})
R fold(R initialValue, R Function(R previousValue, E element) combine)
Iterable followedBy(Iterable other)
void forEach(void Function(E element) action)
bool isEmpty
bool isNotEmpty
Iterator iterator
String join([String separator = ""])
E last
E lastWhere(bool Function(E element) test, {E Function()? orElse})
int length
Iterable map(R Function(E e) toElement)
E reduce(E Function(E value, E element) combine)
E single
E singleWhere(bool Function(E element) test, {E Function()? orElse})
Iterable skip(int count)
Iterable skipWhile(bool Function(E value) test)
Iterable take(int count)
Iterable takeWhile(bool Function(E value) test)
List toList({bool growable = true})
Set toSet()
Iterable where(bool Function(E element) test)
Iterable whereType()