๐ Filtering Collection Observable
Available Since 0.0.46
Introduction
Sometimes we want to derive a live view of a collection by filtering its elements based on an Observable<Boolean> owned by each element.
This is different from a simple Predicate<E> filter, because the membership of each element can change over time (for example: a player becomes alive/dead, online/offline) and the filtered collection should update automatically.
Usage
Expected behavior
When an element is added to the source collection:
Subscribe to its predicate observable
Include/exclude it based on the current predicate value
When an element is removed from the source collection:
Unsubscribe from its predicate observable
Remove it from the filtered collection
When the predicate observable changes:
true: element appears in filtered viewfalse: element disappears from filtered view
Notes per collection type
Source | Result | Element duplication |
|---|---|---|
|
| Source order and multiplicity preserved — each occurrence is included/excluded independently |
|
| The source already deduplicates by element |
Advantages
โ Live subset view: Always up-to-date without manual bookkeeping
๐ง Reactive membership: Elements can enter/leave the view when their internal state changes
๐งน No observer leaks: Observers are removed when elements leave the source collection
โก Efficient updates: Updates only the impacted elements rather than recomputing everything
โ Chaining: Can be chained with other operators