Skip to content

Commit 808b4bb

Browse files
committed
address docstring-related review comments
1 parent 290f499 commit 808b4bb

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

effect/fold.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,24 @@ def __str__(self):
2525

2626
def 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``.

effect/test_fold.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,15 @@
1111

1212

1313
def _disp(dispatcher):
14+
"""Compose base_dispatcher onto the given dispatcher."""
1415
return ComposedDispatcher([dispatcher, base_dispatcher])
1516

1617

1718
def 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([

0 commit comments

Comments
 (0)