lisa.monad.StateDiscard#

class lisa.monad.StateDiscard(f)[source]#

Bases: State

Same as State except that calling monadic values will return the computed value instead of a tuple (value, state).

This is useful for APIs where the final state is of no interest to the user.

Attributes

__slots__ inherited

Properties

f inherited

State-transforming function of type state -> (value, new_state).

Methods

__call__()

Allow calling monadic values to run the state-transforming function, with the initial state provided by State.make_state().

bind()

Takes a monadic value Monad[A], a function that takes an A and returns Monad[B], and returns a Monad[B].

__await__() inherited

do() inherited

Decorate a coroutine function so that awaits gains the powers of the monad.

from_f() inherited

Build a monadic value out of a state modifying function of type state -> (value, new_state).

get_state() inherited

Returns a monadic value returning the current state.

hoist() inherited

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).

join() inherited

Takes a monadic value Monad[Monad[A]], and returns a Monad[A].

lift() inherited

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).

make_state() inherited

Create an initial state. All the parameters of State.__call__() are passed to State.make_state().

map() inherited

Takes a monadic value Monad[A], a function that takes an A and returns B, and returns a Monad[B].

modify_state() inherited

Returns a monadic value applying f on the current state, setting the new state and then returning it.

pure() inherited

Turn a regular value of type A into a monadic value of type Monad[A].

set_state() inherited

Returns a monadic value setting the current state and returning the old one.

Attributes#

StateDiscard.__slots__ = ('_f',)#

Properties#

property StateDiscard.f#

Inherited property, see lisa.monad.State.f

State-transforming function of type state -> (value, new_state).

Methods#

StateDiscard.__call__(*args, **kwargs)[source]#

Allow calling monadic values to run the state-transforming function, with the initial state provided by State.make_state().

StateDiscard.bind(continuation)#

Takes a monadic value Monad[A], a function that takes an A and returns Monad[B], and returns a Monad[B].

Note

It is allowed to return a _TailCall instance.

StateDiscard.__await__()#

Inherited method, see lisa.monad.Monad.__await__()

classmethod StateDiscard.do(f)#

Inherited method, see lisa.monad.MonadTrans.do()

Decorate a coroutine function so that awaits gains the powers of the monad.

classmethod StateDiscard.from_f(f)#

Inherited method, see lisa.monad.State.from_f()

Build a monadic value out of a state modifying function of type state -> (value, new_state).

classmethod StateDiscard.get_state()#

Inherited method, see lisa.monad.State.get_state()

Returns a monadic value returning the current state.

classmethod StateDiscard.hoist(self, nat)#

Inherited method, see lisa.monad.State.hoist()

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).

classmethod StateDiscard.join(self)#

Inherited method, see lisa.monad.Monad.join()

Takes a monadic value Monad[Monad[A]], and returns a Monad[A].

classmethod StateDiscard.lift(m)#

Inherited method, see lisa.monad.State.lift()

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).

classmethod StateDiscard.make_state(x)#

Inherited method, see lisa.monad.State.make_state()

Create an initial state. All the parameters of State.__call__() are passed to State.make_state().

classmethod StateDiscard.map(self, f)#

Inherited method, see lisa.monad.Monad.map()

Takes a monadic value Monad[A], a function that takes an A and returns B, and returns a Monad[B].

classmethod StateDiscard.modify_state(f)#

Inherited method, see lisa.monad.State.modify_state()

Returns a monadic value applying f on the current state, setting the new state and then returning it.

classmethod StateDiscard.pure(x)#

Inherited method, see lisa.monad.MonadTrans.pure()

Turn a regular value of type A into a monadic value of type Monad[A].

classmethod StateDiscard.set_state(new)#

Inherited method, see lisa.monad.State.set_state()

Returns a monadic value setting the current state and returning the old one.