SavedStateKt

Added in 1.3.0-alpha04

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 T
<T extends Object> read(
    @NonNull SavedStateWriter 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 SavedStateReader

Creates a new SavedStateReader for the SavedState.

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.

static final @NonNull T
<T extends Object> write(
    @NonNull SavedStateReader 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.

static final @NonNull SavedStateWriter

Creates a new SavedStateWriter for the SavedState.

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.

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 T <T extends Object> read(
    @NonNull SavedStateWriter 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.

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 SavedStateReader reader(@NonNull SavedState receiver)

Creates a new SavedStateReader for the SavedState.

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.

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.

public static final @NonNull T <T extends Object> write(
    @NonNull SavedStateReader 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.

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.

public static final @NonNull SavedStateWriter writer(@NonNull SavedState receiver)

Creates a new SavedStateWriter for the SavedState.