brainstate.maybe_state

Contents

brainstate.maybe_state#

brainstate.maybe_state(val)[source]#

Extracts the value from a State object if given, otherwise returns the input value.

This function is useful for handling both State objects and raw values uniformly. If the input is a State object, it returns the value stored in that State. If the input is not a State object, it returns the input as is.

Parameters:

val (Any) – The input value, which can be either a State object or any other type.

Returns:

The value stored in the State if the input is a State object,

otherwise the input value itself.

Return type:

Any