.. title:: State lisa.monad.State ================ .. autoclass:: lisa.monad::State :no-members: :no-inherited-members: :no-undoc-members: :no-private-members: :no-special-members: .. rubric:: Attributes .. list-table:: :align: left * - :attr:`~lisa.monad.State.__slots__` - .. withrefctx:: :module: lisa.monad :class: lisa.monad.State .. rubric:: Properties .. list-table:: :align: left * - :attr:`~lisa.monad.State.f` - .. withrefctx:: :module: lisa.monad :class: lisa.monad.State State-transforming function of type ``state -> (value, new_state)``. .. rubric:: Methods .. list-table:: :align: left * - :meth:`~lisa.monad.State.__call__` - .. withrefctx:: :module: lisa.monad :class: lisa.monad.State Allow calling monadic values to run the state-transforming function, with the initial state provided by :meth:`State.make_state`. * - :meth:`~lisa.monad.State.bind` - .. withrefctx:: :module: lisa.monad :class: lisa.monad.State Takes a monadic value Monad[A], a function that takes an A and returns Monad[B], and returns a Monad[B]. * - :meth:`~lisa.monad.State.from_f` - .. withrefctx:: :module: lisa.monad :class: lisa.monad.State Build a monadic value out of a state modifying function of type ``state -> (value, new_state)``. * - :meth:`~lisa.monad.State.get_state` - .. withrefctx:: :module: lisa.monad :class: lisa.monad.State Returns a monadic value returning the current state. * - :meth:`~lisa.monad.State.hoist` - .. withrefctx:: :module: lisa.monad :class: lisa.monad.State Lift a monadic value ``m`` by one level in the stack, i.e.: Given a stack for 3 transformers ``T1(T2(T3(Identity)))``, a value ``m = T2(Identity).pure(42)``. we have ``T2.hoist(m, T3.pure) == T2(T3(Identity)).pure(42)``. * - :meth:`~lisa.monad.State.lift` - .. withrefctx:: :module: lisa.monad :class: lisa.monad.State Lift a monadic value ``m`` by one level in the stack, i.e.: Given a stack for 3 transformers ``T1(T2(T3(Identity)))``, a value ``m = T3(Identity).pure(42)``. we have ``T2.lift(m) == T2(T3(Identity)).pure(42)``. * - :meth:`~lisa.monad.State.make_state` - .. withrefctx:: :module: lisa.monad :class: lisa.monad.State Create an initial state. All the parameters of :meth:`State.__call__` are passed to :meth:`State.make_state`. * - :meth:`~lisa.monad.State.modify_state` - .. withrefctx:: :module: lisa.monad :class: lisa.monad.State Returns a monadic value applying ``f`` on the current state, setting the new state and then returning it. * - :meth:`~lisa.monad.State.set_state` - .. withrefctx:: :module: lisa.monad :class: lisa.monad.State Returns a monadic value setting the current state and returning the old one. * - :meth:`~lisa.monad.Monad.__await__` :sup:`inherited` - .. withrefctx:: :module: lisa.monad :class: lisa.monad._MonadBase * - :meth:`~lisa.monad.MonadTrans.do` :sup:`inherited` - .. withrefctx:: :module: lisa.monad :class: lisa.monad.MonadTrans Decorate a coroutine function so that ``awaits`` gains the powers of the monad. * - :meth:`~lisa.monad.Monad.join` :sup:`inherited` - .. withrefctx:: :module: lisa.monad :class: lisa.monad.Monad Takes a monadic value Monad[Monad[A]], and returns a Monad[A]. * - :meth:`~lisa.monad.Monad.map` :sup:`inherited` - .. withrefctx:: :module: lisa.monad :class: lisa.monad.Monad Takes a monadic value Monad[A], a function that takes an A and returns B, and returns a Monad[B]. * - :meth:`~lisa.monad.MonadTrans.pure` :sup:`inherited` - .. withrefctx:: :module: lisa.monad :class: lisa.monad.MonadTrans Turn a regular value of type ``A`` into a monadic value of type ``Monad[A]``. Attributes ---------- .. autoattribute:: lisa.monad::State.__slots__ Properties ---------- .. autoproperty:: lisa.monad::State.f Methods ------- .. automethod:: lisa.monad::State.__call__ .. automethod:: lisa.monad::State.bind .. automethod:: lisa.monad::State.from_f .. automethod:: lisa.monad::State.get_state .. automethod:: lisa.monad::State.hoist .. automethod:: lisa.monad::State.lift .. automethod:: lisa.monad::State.make_state .. automethod:: lisa.monad::State.modify_state .. automethod:: lisa.monad::State.set_state .. automethod:: lisa.monad::State.__await__ .. automethod:: lisa.monad::State.do .. automethod:: lisa.monad::State.join .. automethod:: lisa.monad::State.map .. automethod:: lisa.monad::State.pure