You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The type parameter `A` is present because some schedules may require abilities to complete.
547
547
548
-
The `stateless.schedule` module contains a number of of helpful implemenations of `Schedule`, for example `Spaced` or `Recurs`.
548
+
The `stateless.schedule` module contains a number of of helpful implementations of `Schedule`, for example `spaced` or `recurs`.
549
549
550
550
Schedules can be used with the `repeat` decorator, which takes schedule as its first argument and repeats the decorated function returning an effect until the schedule is exhausted or an error occurs:
551
551
552
552
```python
553
553
from datetime import timedelta
554
554
555
555
from stateless import repeat, success, Success, supply, run
556
-
from stateless.schedule importRecurs, Spaced
556
+
from stateless.schedule importrecurs, spaced
557
557
from stateless.time import Time
558
558
559
559
560
-
@repeat(Recurs(2, Spaced(timedelta(seconds=2))))
560
+
@repeat(recurs(2, spaced(timedelta(seconds=2))))
561
561
deff() -> Success[str]:
562
562
return success("hi!")
563
563
@@ -574,7 +574,7 @@ This is a useful pattern because such objects can be yielded from in functions r
574
574
575
575
```python
576
576
defthis_works() -> Success[timedelta]:
577
-
schedule =Spaced(timedelta(seconds=2))
577
+
schedule =spaced(timedelta(seconds=2))
578
578
deltas =yield from schedule
579
579
deltas_again =yield from schedule # safe!
580
580
return deltas
@@ -589,14 +589,14 @@ when the decorated function yields no errors, or fails when the schedule is exha
589
589
from datetime import timedelta
590
590
591
591
from stateless import retry, throw, Try, throw, success, supply, run
592
-
from stateless.schedule importRecurs, Spaced
592
+
from stateless.schedule importrecurs, spaced
593
593
from stateless.time import Time
594
594
595
595
596
596
fail =True
597
597
598
598
599
-
@retry(Recurs(2, Spaced(timedelta(seconds=2))))
599
+
@retry(recurs(2, spaced(timedelta(seconds=2))))
600
600
deff() -> Try[RuntimeError, str]:
601
601
global fail
602
602
if fail:
@@ -670,10 +670,7 @@ Moreover, monads famously do not compose, meaning that when writing code that ne
670
670
671
671
Additionally, in languages with dynamic binding such as Python, calling functions is relatively expensive, which means that using callbacks as the principal method for resuming computation comes with a fair amount of performance overhead.
672
672
673
-
Finally, interpreting monads is often a recursive procedure, meaning that it's necessary to worry about stack safety in languages without tail call optimisation such as Python. This is usually solved using [trampolines](https://en.wikipedia.org/wiki/Trampoline_(computing)) which further adds to the performance overhead.
674
-
675
-
676
-
Because of all these practical challenges of programming with monads, people have been looking for alternatives. Algebraic effects is one the things suggested that address many of the challenges of monadic effect systems.
673
+
Because of all these practical challenges of programming with monads, people have been looking for alternatives. Algebraic effects is one suggested solution that address many of the challenges of monadic effect systems.
677
674
678
675
In algebraic effect systems, such as `stateless`, the programmer still supplies the effect system with a description of the side-effect to be carried out, but instead of supplying a callback function to resume the
679
676
computation with, the result of handling the effect is returned to the point in program execution that the effect description was produced. The main drawback of this approach is that it requires special language features to do this. In Python however, such a language feature _does_ exist: Generators and coroutines.
0 commit comments