Documentation
¶
Index ¶
- func CollectAsState[T any](c api.Composer, flow Flow[T], initial T) state.TypedValue[T]
- func CollectStateFlowAsState[T any](c api.Composer, flow StateFlow[T]) state.TypedValue[T]
- func First[T any](ctx context.Context, flow Flow[T]) (T, error)
- func ToList[T any](ctx context.Context, flow Flow[T]) ([]T, error)
- type Flow
- func Combine[T1, T2, R any](ctx context.Context, flow1 Flow[T1], flow2 Flow[T2], transform func(T1, T2) R) Flow[R]
- func Map[T, R any](upstream Flow[T], transform func(T) R) Flow[R]
- func NewFlow[T any](block func(ctx context.Context, emit func(T)) error) Flow[T]
- func Zip[T1, T2, R any](ctx context.Context, flow1 Flow[T1], flow2 Flow[T2], transform func(T1, T2) R) Flow[R]
- type MutableStateFlow
- func (s *MutableStateFlow[T]) AsStateFlow() StateFlow[T]
- func (s *MutableStateFlow[T]) Collect(ctx context.Context, collector func(T)) error
- func (s *MutableStateFlow[T]) Emit(value T)
- func (s *MutableStateFlow[T]) Subscribe(callback func()) state.Subscription
- func (s *MutableStateFlow[T]) Update(f func(current T) T)
- func (s *MutableStateFlow[T]) Value() T
- type StateFlow
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CollectAsState ¶
CollectAsState collects values from a Flow and represents it as a State. The initial value is used until the first value is emitted by the flow.
func CollectStateFlowAsState ¶
CollectStateFlowAsState collects values from a StateFlow. It uses `flow.Value()` as the initial value.
Types ¶
type Flow ¶
Flow represents a cold stream of data.
type MutableStateFlow ¶
type MutableStateFlow[T any] struct { // contains filtered or unexported fields }
MutableStateFlow is the hot, stateful producer
func NewMutableStateFlow ¶
func NewMutableStateFlow[T any](initial T) *MutableStateFlow[T]
func (*MutableStateFlow[T]) AsStateFlow ¶
func (s *MutableStateFlow[T]) AsStateFlow() StateFlow[T]
func (*MutableStateFlow[T]) Collect ¶
func (s *MutableStateFlow[T]) Collect(ctx context.Context, collector func(T)) error
Collect follows the Kotlin pattern: it blocks until the context is cancelled
func (*MutableStateFlow[T]) Emit ¶
func (s *MutableStateFlow[T]) Emit(value T)
Emit updates the value and notifies all collectors and state subscribers.
func (*MutableStateFlow[T]) Subscribe ¶ added in v0.1.68
func (s *MutableStateFlow[T]) Subscribe(callback func()) state.Subscription
Subscribe registers a callback to be invoked when the flow's value changes. This implements state.StateChangeNotifier, enabling MutableStateFlow to be used as a dependency for DerivedState.
func (*MutableStateFlow[T]) Update ¶
func (s *MutableStateFlow[T]) Update(f func(current T) T)
Update provides an atomic way to modify state (like Kotlin's .update { ... })
func (*MutableStateFlow[T]) Value ¶
func (s *MutableStateFlow[T]) Value() T
Value returns the current state (Thread-safe) Also notifies the read observer to enable derived state dependency tracking.