πΏ Immutable & Empty Observable
Available Since 0.0.39
Introduction
Observer#immutable returns a simple implementation of the Observable<T> interface that always returns a fixed value. It never becomes dirty and does not trigger re-computation or notify observers. This makes it ideal for constant values within a reactive system, naturally bridging the gap between the two.
Usage
You can also use immutable observables as part of mapped or compound observables to combine constants with dynamic values.
How it works
An immutable observable holds a single value and implements the Observable<T> interface. Since the value never changes, calling Observable#get() will always return the same result without marking it as dirty or notifying any observers.
It effectively acts as a no-op in the dependency graph — useful for simplifying logic where a value is static, but uniformity with other observables is desired.
This is functionally similar to using a mutable observable value but not changing its value, with some performance benefits.
Empty Observable
Based on the immutable observer implementation is another special use case for it under Observable#empty(). It acts like any other immutable observable but with a null value. It is recommended for memory usage and future micro optimizations.
Advantages
βοΈ Zero overhead: No re-computation, no dirty state.
π Safe & predictable: Guaranteed to never change.
π§± Composable: Works seamlessly with mapped and compound observables.
π οΈ Ideal for constants: Use to represent fixed values in reactive trees.