Skip to content

Commit 8d7ee79

Browse files
committed
test for empty case & cleanup
1 parent 9f24303 commit 8d7ee79

2 files changed

Lines changed: 13 additions & 7 deletions

File tree

effect/fold.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,5 @@ def folder(acc, element):
2525

2626

2727
def sequence(effects):
28-
def folder(acc, element):
29-
return acc + [element]
30-
return fold_effect(folder, [], effects)
28+
"""Perform each Effect serially, collecting their results into a list."""
29+
return fold_effect(lambda acc, el: acc + [el], [], effects)

effect/test_fold.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
from effect.testing import SequenceDispatcher
77

88

9+
def _disp(dispatcher):
10+
return ComposedDispatcher([dispatcher, base_dispatcher])
11+
912
def test_fold_effect():
1013
"""Behaves like foldM."""
1114
effs = [Effect('a'), Effect('b'), Effect('c')]
@@ -18,9 +21,7 @@ def test_fold_effect():
1821
eff = fold_effect(operator.add, 'Nil', effs)
1922

2023
with dispatcher.consume():
21-
result = sync_perform(
22-
ComposedDispatcher([dispatcher, base_dispatcher]),
23-
eff)
24+
result = sync_perform(_disp(dispatcher), eff)
2425
assert result == 'NilEiBeeCee'
2526

2627

@@ -34,6 +35,7 @@ def test_fold_effect_empty():
3435

3536

3637
def test_sequence():
38+
"""Collects each Effectful result into a list."""
3739
effs = [Effect('a'), Effect('b'), Effect('c')]
3840
dispatcher = SequenceDispatcher([
3941
('a', lambda i: 'Ei'),
@@ -44,5 +46,10 @@ def test_sequence():
4446

4547
print "what the heck is sequence returning?", eff
4648
with dispatcher.consume():
47-
result = sync_perform(dispatcher, eff)
49+
result = sync_perform(_disp(dispatcher), eff)
4850
assert result == ['Ei', 'Bee', 'Cee']
51+
52+
53+
def test_sequence_empty():
54+
"""Returns an empty list when there are no Effects."""
55+
assert sync_perform(base_dispatcher, sequence([])) == []

0 commit comments

Comments
 (0)