
# Collections

A `@Signal` field that holds a `List`, a `Set`, a `Map` or a `Queue` is handed out as a collection that tells its readers of a change in place.

## Why

A list is rarely assigned: it is added to, sorted, cleared. If only an assignment were a change, every method would end with `items = [...items]`, and one forgotten would leave the screen stale.

## Example

```dart
@Signal()
List<Book> items = [];

void add(Book book) => items.add(book);     // told, without an assignment
```

## What is a change

- **A change in place**: `items.add(book)`, `items.clear()`, a sort. From outside the bean too: `basket.items.add(book)`.
- **An assignment of another collection**:

```dart
void remove(String title) => items = [
  for (final book in items)
    if (book.title != title) book,
];
```

- **What the getter handed out, assigned back**: `items = items..sort()`. The field keeps the same list.

One change in place is told once, however many elements it moved. A `Set` tells only of what changed it: adding an element already there tells nobody.

## What stays

The field keeps the collection itself, and its type stays what was written: `basket.items` is a `List<Book>`.

## See also

- [Fields and computed values](fields-and-computed.md)
- [Effects](effects.md): one change for a method
