SavedStateKt

Added in 1.3.0-alpha05

public final class SavedStateKt


Summary

Public methods

static final @NonNull T
<T extends Object> read(
    @NonNull SavedState receiver,
    @ExtensionFunctionType @NonNull Function1<@NonNull SavedStateReader, @NonNull T> block
)

Calls the specified function block with a SavedStateReader value as its receiver and returns the block value.

static final @NonNull SavedState
savedState(
    @NonNull Map<@NonNull StringObject> initialState,
    @ExtensionFunctionType @NonNull Function1<@NonNull SavedStateWriterUnit> builderAction
)

Builds a new SavedState with the specified initialState, given as a Map of String keys and Any value.

static final @NonNull T
<T extends Object> write(
    @NonNull SavedState receiver,
    @ExtensionFunctionType @NonNull Function1<@NonNull SavedStateWriter, @NonNull T> block
)

Calls the specified function block with a SavedStateWriter value as its receiver and returns the block value.

Public methods

public static final @NonNull T <T extends Object> read(
    @NonNull SavedState receiver,
    @ExtensionFunctionType @NonNull Function1<@NonNull SavedStateReader, @NonNull T> block
)

Calls the specified function block with a SavedStateReader value as its receiver and returns the block value.

IMPORTANT: The SavedStateReader passed as a receiver to the block is valid only inside that function. Using it outside of the function may produce an unspecified behavior.

Parameters
@ExtensionFunctionType @NonNull Function1<@NonNull SavedStateReader, @NonNull T> block

A lambda function that performs read operations using the SavedStateReader.

Returns
@NonNull T

The result of the lambda function's execution.

public static final @NonNull SavedState savedState(
    @NonNull Map<@NonNull StringObject> initialState,
    @ExtensionFunctionType @NonNull Function1<@NonNull SavedStateWriterUnit> builderAction
)

Builds a new SavedState with the specified initialState, given as a Map of String keys and Any value.

Allows further modification of the state using the builderAction.

IMPORTANT: The SavedStateWriter passed as a receiver to the builderAction is valid only inside that function. Using it outside of the function may produce an unspecified behavior.

Parameters
@NonNull Map<@NonNull StringObject> initialState

An initial map of key-value pairs to populate the state. Defaults to an empty map.

@ExtensionFunctionType @NonNull Function1<@NonNull SavedStateWriterUnit> builderAction

A lambda function with a SavedStateWriter receiver to modify the state.

Returns
@NonNull SavedState

A SavedState instance containing the initialized key-value pairs.

public static final @NonNull T <T extends Object> write(
    @NonNull SavedState receiver,
    @ExtensionFunctionType @NonNull Function1<@NonNull SavedStateWriter, @NonNull T> block
)

Calls the specified function block with a SavedStateWriter value as its receiver and returns the block value.

IMPORTANT: The SavedStateWriter passed as a receiver to the block is valid only inside that function. Using it outside of the function may produce an unspecified behavior.

Parameters
@ExtensionFunctionType @NonNull Function1<@NonNull SavedStateWriter, @NonNull T> block

A lambda function that performs write operations using the SavedStateWriter.

Returns
@NonNull T

The result of the lambda function's execution.