ð Collection Observable Conversion
Available Since 0.0.50
Introduction
as is a conversion operator on CollectionObservable that transforms a collection observable into a different collection type using a ObservableCollectionType.
For example, you can derive a SetObservable from a ListObservable — duplicates are automatically collapsed, and the result stays in sync with the source:
The ObservableCollectionType utility class provides ready-made collectors for common conversions.
Usage
Built-in collectors
Method | Source | Result | Default snapshot | Default collection |
|---|---|---|---|---|
| any |
|
|
|
| any |
|
|
|
Both methods also accept custom factory functions for the snapshot and mutable-collection creation, so you can use a LinkedHashSet, CopyOnWriteArrayList, or any other implementation:
Behavior
The derived collection is read-only —
add,remove,addAll,removeAll,removeIf,retainAll,clearall throwUnsupportedOperationException.Snapshots returned by
get()are immutable and cached — the snapshot is only recomputed when the source collection changes.Previous snapshots are not affected by later source changes; they remain a frozen view of the collection at the time they were obtained.
Derived collections support chaining with other operators like
mapEach,flatMapEach, andfilter.
Advantages
ð Live conversion: always reflects the latest state of the source collection
ð§ Stable snapshots: each
get()result is immutable and won't change under youð§ą Composable: the result is a full
CollectionObservable— chainfilter,mapEach, etc.ð Extensible: implement your own
ObservableCollectionTypefor custom collection typesðŠķ Lazy: conversion only happens when
get()is called and the source has changed