Skip to content

Commit c03012f

Browse files
committed
Merge branch 'master' into sequence
2 parents b3f0456 + ccd273b commit c03012f

22 files changed

Lines changed: 36 additions & 727 deletions

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
lint:
2-
flake8 --ignore=E131,E731,W503 effect/ examples/
2+
flake8 --ignore=E131,E731,W503 effect/
33

44
build-dist:
55
rm -rf dist

README.rst

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Effect
22
======
33

4-
.. image:: https://travis-ci.org/radix/effect.svg?branch=master
5-
:target: https://travis-ci.org/radix/effect
4+
.. image:: https://travis-ci.org/python-effect/effect.svg?branch=master
5+
:target: https://travis-ci.org/python-effect/effect
66

77
Effect is a library for helping you write purely functional code by
88
isolating the effects (that is, IO or state manipulation) in your code.
@@ -89,10 +89,10 @@ possible to override the way an intent is performed to do whatever you want.
8989
For more information on how to implement the actual effect-performing code,
9090
and other details, see the `documentation`_. There is also a full example
9191
of interacting with the user and using an HTTP client to talk to the GitHub
92-
API in the `examples`_ directory.
92+
API in the `effect-examples`_ repository.
9393

9494
.. _`documentation`: https://effect.readthedocs.org/
95-
.. _`examples`: https://github.com/radix/effect/tree/master/examples
95+
.. _`effect-examples`: https://github.com/python-effect/effect-examples
9696

9797

9898

@@ -133,6 +133,12 @@ There is a ``#python-effect`` IRC channel on irc.freenode.net.
133133
See Also
134134
========
135135

136+
For integrating Effect with Twisted's Deferreds, see the ``txEffect`` package
137+
(`pypi`_, `github`_).
138+
139+
.. _`pypi`: https://warehouse.python.org/project/txeffect
140+
.. _`github`: https://github.com/python-effect/txeffect
141+
136142
Over the past few years, the ecosystem of libraries to help with functional
137143
programming in Python has exploded. Here are some libraries I recommend:
138144

dev-requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
testtools
2-
twisted
32
flake8
43
pytest

docs/source/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@
6060
# built documents.
6161
#
6262
# The short X.Y version.
63-
version = '0.1a18'
63+
version = '0.1a19'
6464
# The full version, including alpha/beta/rc tags.
65-
release = '0.1a18'
65+
release = '0.1a19'
6666

6767
# The language for content autogenerated by Sphinx. Refer to documentation
6868
# for a list of supported languages.

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: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,16 @@
1010
from effect.testing import SequenceDispatcher
1111

1212

13-
def _disp(dispatcher):
13+
def _base_and(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([
@@ -26,7 +30,7 @@ def test_fold_effect():
2630
eff = fold_effect(operator.add, 'Nil', effs)
2731

2832
with dispatcher.consume():
29-
result = sync_perform(_disp(dispatcher), eff)
33+
result = sync_perform(_base_and(dispatcher), eff)
3034
assert result == 'NilEiBeeCee'
3135

3236

@@ -54,7 +58,7 @@ def test_fold_effect_errors():
5458

5559
with dispatcher.consume():
5660
with raises(FoldError) as excinfo:
57-
sync_perform(_disp(dispatcher), eff)
61+
sync_perform(_base_and(dispatcher), eff)
5862
assert excinfo.value.accumulator == 'NilEi'
5963
assert excinfo.value.wrapped_exception[0] is ZeroDivisionError
6064
assert str(excinfo.value.wrapped_exception[1]) == 'foo'

effect/test_twisted.py

Lines changed: 0 additions & 224 deletions
This file was deleted.

0 commit comments

Comments
 (0)