flow

package
v0.1.59 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 13, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CollectAsState

func CollectAsState[T any](c api.Composer, flow Flow[T], initial T) state.TypedValue[T]

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

func CollectStateFlowAsState[T any](c api.Composer, flow StateFlow[T]) state.TypedValue[T]

CollectStateFlowAsState collects values from a StateFlow. It uses `flow.Value()` as the initial value.

func First

func First[T any](ctx context.Context, flow Flow[T]) (T, error)

First returns the first value emitted by the flow and then stops.

func ToList

func ToList[T any](ctx context.Context, flow Flow[T]) ([]T, error)

ToList collects all values from a flow and returns them as a slice.

Types

type Flow

type Flow[T any] interface {
	Collect(ctx context.Context, collector func(T)) error
}

Flow represents a cold stream of data.

func Combine

func Combine[T1, T2, R any](
	ctx context.Context,
	flow1 Flow[T1],
	flow2 Flow[T2],
	transform func(T1, T2) R,
) Flow[R]

func Map

func Map[T, R any](upstream Flow[T], transform func(T) R) Flow[R]

func NewFlow

func NewFlow[T any](block func(ctx context.Context, emit func(T)) error) Flow[T]

NewFlow creates a cold flow. The 'block' isn't executed until Collect is called.

func Zip

func Zip[T1, T2, R any](
	ctx context.Context,
	flow1 Flow[T1],
	flow2 Flow[T2],
	transform func(T1, T2) R,
) Flow[R]

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

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)

type StateFlow

type StateFlow[T any] interface {
	Value() T
	Flow[T]
}

StateFlow defines the read-only behavior

Directories

Path Synopsis
demo
stateflow command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL