44.. image :: https://travis-ci.org/python-effect/effect.svg?branch=master
55 :target: https://travis-ci.org/python-effect/effect
66
7- Effect is a library for helping you write purely functional code by
8- isolating the effects (that is, IO or state manipulation) in your code.
9- Documentation is available at https://effect.readthedocs.org/.
10-
11- .. image :: https://radix.github.io/effect/sigh-defects.png
12- :target: https://twitter.com/extempore2/status/553597279463305218
7+ Effect is a library for helping you write purely functional code by isolating
8+ the effects (that is, IO or state manipulation) in your code. Documentation is
9+ available at https://effect.readthedocs.org/, and its PyPI page is
10+ https://pypi.python.org/pypi/effect.
1311
12+ It `supports `_ both Python 2.6 and up, and 3.4 and up, as well as PyPy.
1413
14+ .. _`supports` : https://travis-ci.org/python-effect/effect
1515
16- Status: Alpha
17- =============
16+ You can install it by running ``pip install effect ``.
1817
19- Right now Effect is in alpha, and is likely to change incompatibly. Once it's
20- being used in production and the API seems pretty good, a final version will be
21- released. Because it's in alpha, ``pip `` requires that you explicitly specify
22- the version number when specifying a dependency. This means that you won't
23- automatically get upgraded to newer versions that potentially break the API.
24- e.g., use `pip install effect==0.1aN `.
18+ .. image :: https://radix.github.io/effect/sigh-defects.png
19+ :target: https://twitter.com/extempore2/status/553597279463305218
2520
2621
2722What Is It?
2823===========
2924
30- Effect lets you isolate your IO and state-manipulation code, by using a system
31- very similar to Haskell's `extensible-effects `_ package. It also has
32- similarities to Twisted's Deferred objects.
33-
34- .. _`extensible-effects` : https://hackage.haskell.org/package/extensible-effects
25+ Effect lets you isolate your IO and state-manipulation code.
3526
3627The benefits of this are many: first, the majority of your code can become
3728purely functional, leading to easier testing and ability to reason about
3829behavior. Also, because it separates the specification of an effect from the
3930performance of the effect, there are two more benefits: testing becomes easier
4031still, and it's easy to provide alternative implementations of effects.
4132
33+ Effect is somewhat similar to "algebraic effects", as implemented in various
34+ typed functional programming languages. It also has similarities to Twisted's
35+ Deferred objects.
4236
4337Example
4438=======
@@ -51,27 +45,27 @@ A very quick example of using Effects:
5145 from effect import perform, sync_performer, Effect, TypeDispatcher
5246
5347 class ReadLine (object ):
54- def __init__ (self , prompt ):
55- self .prompt = prompt
48+ def __init__ (self , prompt ):
49+ self .prompt = prompt
5650
5751 def get_user_name ():
58- return Effect(ReadLine(" Enter a candy> " ))
52+ return Effect(ReadLine(" Enter a candy> " ))
5953
6054 @sync_performer
6155 def perform_read_line (dispatcher , readline ):
62- return raw_input (readline.prompt)
56+ return raw_input (readline.prompt)
6357
6458 def main ():
65- effect = get_user_name()
66- effect = effect.on(
67- success = lambda result : print (" I like {} too!" .format(result)),
68- error = lambda e : print (" sorry, there was an error. {} " .format(e)))
59+ effect = get_user_name()
60+ effect = effect.on(
61+ success = lambda result : print (" I like {} too!" .format(result)),
62+ error = lambda e : print (" sorry, there was an error. {} " .format(e)))
6963
70- dispatcher = TypeDispatcher({ReadLine: perform_read_line})
71- perform(dispatcher, effect)
64+ dispatcher = TypeDispatcher({ReadLine: perform_read_line})
65+ perform(dispatcher, effect)
7266
7367 if __name__ == ' __main__' :
74- main()
68+ main()
7569
7670
7771 ``Effect `` takes what we call an ``intent ``, which is any object. The
0 commit comments