File tree Expand file tree Collapse file tree 2 files changed +18
-3
lines changed
Expand file tree Collapse file tree 2 files changed +18
-3
lines changed Original file line number Diff line number Diff line change @@ -25,13 +25,24 @@ def __str__(self):
2525
2626def fold_effect (f , initial , effects ):
2727 """
28- Fold over effects.
28+ Fold over the results of effects, left-to-right .
2929
30- The function will be called with the accumulator (starting with
30+ This is like :func:`functools.reduce`, but instead of acting on plain
31+ values, it acts on the results of effects.
32+
33+ The function ``f`` will be called with the accumulator (starting with
3134 ``initial``) and a result of an effect repeatedly for each effect. The
3235 result of the previous call will be passed as the accumulator to the next
3336 call.
3437
38+ For example, the following code evaluates to an Effect of 6::
39+
40+ fold_effect(operator.add, 0, [Effect(Constant(1)),
41+ Effect(Constant(2)),
42+ Effect(Constant(3))])
43+
44+ If no elements were in the list, Effect would result in 0.
45+
3546 :param callable f: function of ``(accumulator, element) -> accumulator``
3647 :param initial: The value to be passed as the accumulator to the first
3748 invocation of ``f``.
Original file line number Diff line number Diff line change 1111
1212
1313def _disp (dispatcher ):
14+ """Compose base_dispatcher onto the given dispatcher."""
1415 return ComposedDispatcher ([dispatcher , base_dispatcher ])
1516
1617
1718def test_fold_effect ():
18- """Behaves like foldM."""
19+ """
20+ :func:`fold_effect` folds the given function over the results of the
21+ effects.
22+ """
1923 effs = [Effect ('a' ), Effect ('b' ), Effect ('c' )]
2024
2125 dispatcher = SequenceDispatcher ([
You can’t perform that action at this time.
0 commit comments