3.2.1. effect.do module¶
An imperative-looking notation for Effectful code.
See do().
-
effect.do.do(f)¶ A decorator which allows you to use
donotation in your functions, for imperative-looking code:@do def foo(): thing = yield Effect(Constant(1)) return 'the result was %r' % (thing,) eff = foo() return eff.on(...)
@domust decorate a generator function (not any other type of iterator). Any yielded values must be Effects. The result of a yielded Effect will be passed back into the generator as the result of theyieldexpression. A returned value becomes the ultimate result of the Effect that is returned by the decorated function.It’s important to note that any generator function decorated by
@dowill no longer return a generator, but instead it will return an Effect, which must be used just like any other Effect.Errors are also converted to normal exceptions:
@do def foo(): try: thing = yield Effect(Error(RuntimeError('foo'))) except RuntimeError: return 'got a RuntimeError as expected'
(This decorator is named for Haskell’s
donotation, which is similar in spirit).
-
effect.do.do_return(val)¶ Specify a return value for a @do function.
This is deprecated. Just use return.
The result of this function must be yielded. e.g.:
@do def foo(): yield do_return('hello')