lisa.fuzz.GenMonad#
- class lisa.fuzz.GenMonad(f, name=None)[source]#
Bases:
StateDiscard,LoggableRandom generator monad inspired by Haskell’s QuickCheck.
Attributes
__slots__inheritedProperties
finheritedState-transforming function of type
state -> (value, new_state).loggerinheritedConvenience short-hand for
self.get_logger().Methods
Takes a monadic value Monad[A], a function that takes an A and returns Monad[B], and returns a Monad[B].
Initialize the RNG state with either an rng or a seed.
__await__()inherited__call__()inheritedAllow calling monadic values to run the state-transforming function, with the initial state provided by
State.make_state().do()inheritedDecorate a coroutine function so that
awaitsgains the powers of the monad.from_f()inheritedBuild a monadic value out of a state modifying function of type
state -> (value, new_state).get_logger()inheritedProvides a
logging.Loggernamed aftercls.get_state()inheritedReturns a monadic value returning the current state.
hoist()inheritedLift a monadic value
mby one level in the stack, i.e.: Given a stack for 3 transformersT1(T2(T3(Identity))), a valuem = T2(Identity).pure(42). we haveT2.hoist(m, T3.pure) == T2(T3(Identity)).pure(42).join()inheritedTakes a monadic value Monad[Monad[A]], and returns a Monad[A].
lift()inheritedLift a monadic value
mby one level in the stack, i.e.: Given a stack for 3 transformersT1(T2(T3(Identity))), a valuem = T3(Identity).pure(42). we haveT2.lift(m) == T2(T3(Identity)).pure(42).log_locals()inheritedDebugging aid: log the local variables of the calling function.
map()inheritedTakes a monadic value Monad[A], a function that takes an A and returns B, and returns a Monad[B].
modify_state()inheritedReturns a monadic value applying
fon the current state, setting the new state and then returning it.pure()inheritedTurn a regular value of type
Ainto a monadic value of typeMonad[A].set_state()inheritedReturns a monadic value setting the current state and returning the old one.
Attributes#
- GenMonad.__slots__ = ('_f',)#
Properties#
- property GenMonad.f#
Inherited property, see
lisa.monad.State.fState-transforming function of type
state -> (value, new_state).
- property GenMonad.logger#
Inherited property, see
lisa.utils.Loggable.loggerConvenience short-hand for
self.get_logger().
Methods#
- GenMonad.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
_TailCallinstance.
- classmethod GenMonad.make_state(*, rng=None, seed=None)[source]#
Initialize the RNG state with either an rng or a seed.
- Parameters:
seed (object) – Seed to initialize the
random.Randominstance.rng (random.Random) – Instance of RNG.
- GenMonad.__await__()#
Inherited method, see
lisa.monad.Monad.__await__()
- GenMonad.__call__(*args, **kwargs)#
Inherited method, see
lisa.monad.StateDiscard.__call__()Allow calling monadic values to run the state-transforming function, with the initial state provided by
State.make_state().
- classmethod GenMonad.do(f)#
Inherited method, see
lisa.monad.MonadTrans.do()Decorate a coroutine function so that
awaitsgains the powers of the monad.
- classmethod GenMonad.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 GenMonad.get_logger(suffix=None)#
Inherited method, see
lisa.utils.Loggable.get_logger()Provides a
logging.Loggernamed aftercls.
- classmethod GenMonad.get_state()#
Inherited method, see
lisa.monad.State.get_state()Returns a monadic value returning the current state.
- classmethod GenMonad.hoist(self, nat)#
Inherited method, see
lisa.monad.State.hoist()Lift a monadic value
mby one level in the stack, i.e.: Given a stack for 3 transformersT1(T2(T3(Identity))), a valuem = T2(Identity).pure(42). we haveT2.hoist(m, T3.pure) == T2(T3(Identity)).pure(42).
- classmethod GenMonad.join(self)#
Inherited method, see
lisa.monad.Monad.join()Takes a monadic value Monad[Monad[A]], and returns a Monad[A].
- classmethod GenMonad.lift(m)#
Inherited method, see
lisa.monad.State.lift()Lift a monadic value
mby one level in the stack, i.e.: Given a stack for 3 transformersT1(T2(T3(Identity))), a valuem = T3(Identity).pure(42). we haveT2.lift(m) == T2(T3(Identity)).pure(42).
- classmethod GenMonad.log_locals(var_names=None, level='debug')#
Inherited method, see
lisa.utils.Loggable.log_locals()Debugging aid: log the local variables of the calling function.
- classmethod GenMonad.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 GenMonad.modify_state(f)#
Inherited method, see
lisa.monad.State.modify_state()Returns a monadic value applying
fon the current state, setting the new state and then returning it.
- classmethod GenMonad.pure(x)#
Inherited method, see
lisa.monad.MonadTrans.pure()Turn a regular value of type
Ainto a monadic value of typeMonad[A].
- classmethod GenMonad.set_state(new)#
Inherited method, see
lisa.monad.State.set_state()Returns a monadic value setting the current state and returning the old one.