[Python-checkins] cpython (2.7): Issue13443 - Remove the functional module examples from 2.7 (as module is

senthil.kumaran python-checkins at python.org
Thu Dec 22 16:45:17 CET 2011


http://hg.python.org/cpython/rev/c6880edaf6f3
changeset:   74131:c6880edaf6f3
branch:      2.7
parent:      74121:a60a3610a97b
user:        Senthil Kumaran <senthil at uthcode.com>
date:        Thu Dec 22 23:44:53 2011 +0800
summary:
  Issue13443 - Remove the functional module examples from 2.7 (as module is
maintained only till 2.5 and tests had failures with 2.7) and update the links
int the howto document.

files:
  Doc/howto/functional.rst |  149 ++------------------------
  1 files changed, 12 insertions(+), 137 deletions(-)


diff --git a/Doc/howto/functional.rst b/Doc/howto/functional.rst
--- a/Doc/howto/functional.rst
+++ b/Doc/howto/functional.rst
@@ -44,15 +44,14 @@
   functional languages include the ML family (Standard ML, OCaml, and other
   variants) and Haskell.
 
-The designers of some computer languages choose to emphasize one
-particular approach to programming.  This often makes it difficult to
-write programs that use a different approach.  Other languages are
-multi-paradigm languages that support several different approaches.
-Lisp, C++, and Python are multi-paradigm; you can write programs or
-libraries that are largely procedural, object-oriented, or functional
-in all of these languages.  In a large program, different sections
-might be written using different approaches; the GUI might be
-object-oriented while the processing logic is procedural or
+The designers of some computer languages choose to emphasize one particular
+approach to programming.  This often makes it difficult to write programs that
+use a different approach.  Other languages are multi-paradigm languages that
+support several different approaches.  Lisp, C++, and Python are
+multi-paradigm; you can write programs or libraries that are largely
+procedural, object-oriented, or functional in all of these languages.  In a
+large program, different sections might be written using different approaches;
+the GUI might be object-oriented while the processing logic is procedural or
 functional, for example.
 
 In a functional program, input flows through a set of functions. Each function
@@ -1115,132 +1114,6 @@
 Consult the operator module's documentation for a complete list.
 
 
-
-The functional module
----------------------
-
-Collin Winter's `functional module <http://oakwinter.com/code/functional/>`__
-provides a number of more advanced tools for functional programming. It also
-reimplements several Python built-ins, trying to make them more intuitive to
-those used to functional programming in other languages.
-
-This section contains an introduction to some of the most important functions in
-``functional``; full documentation can be found at `the project's website
-<http://oakwinter.com/code/functional/documentation/>`__.
-
-``compose(outer, inner, unpack=False)``
-
-The ``compose()`` function implements function composition.  In other words, it
-returns a wrapper around the ``outer`` and ``inner`` callables, such that the
-return value from ``inner`` is fed directly to ``outer``.  That is, ::
-
-    >>> def add(a, b):
-    ...     return a + b
-    ...
-    >>> def double(a):
-    ...     return 2 * a
-    ...
-    >>> compose(double, add)(5, 6)
-    22
-
-is equivalent to ::
-
-    >>> double(add(5, 6))
-    22
-
-The ``unpack`` keyword is provided to work around the fact that Python functions
-are not always `fully curried <http://en.wikipedia.org/wiki/Currying>`__.  By
-default, it is expected that the ``inner`` function will return a single object
-and that the ``outer`` function will take a single argument. Setting the
-``unpack`` argument causes ``compose`` to expect a tuple from ``inner`` which
-will be expanded before being passed to ``outer``. Put simply, ::
-
-    compose(f, g)(5, 6)
-
-is equivalent to::
-
-    f(g(5, 6))
-
-while ::
-
-    compose(f, g, unpack=True)(5, 6)
-
-is equivalent to::
-
-    f(*g(5, 6))
-
-Even though ``compose()`` only accepts two functions, it's trivial to build up a
-version that will compose any number of functions. We'll use ``reduce()``,
-``compose()`` and ``partial()`` (the last of which is provided by both
-``functional`` and ``functools``). ::
-
-    from functional import compose, partial
-
-    multi_compose = partial(reduce, compose)
-
-
-We can also use ``map()``, ``compose()`` and ``partial()`` to craft a version of
-``"".join(...)`` that converts its arguments to string::
-
-    from functional import compose, partial
-
-    join = compose("".join, partial(map, str))
-
-
-``flip(func)``
-
-``flip()`` wraps the callable in ``func`` and causes it to receive its
-non-keyword arguments in reverse order. ::
-
-    >>> def triple(a, b, c):
-    ...     return (a, b, c)
-    ...
-    >>> triple(5, 6, 7)
-    (5, 6, 7)
-    >>>
-    >>> flipped_triple = flip(triple)
-    >>> flipped_triple(5, 6, 7)
-    (7, 6, 5)
-
-``foldl(func, start, iterable)``
-
-``foldl()`` takes a binary function, a starting value (usually some kind of
-'zero'), and an iterable.  The function is applied to the starting value and the
-first element of the list, then the result of that and the second element of the
-list, then the result of that and the third element of the list, and so on.
-
-This means that a call such as::
-
-    foldl(f, 0, [1, 2, 3])
-
-is equivalent to::
-
-    f(f(f(0, 1), 2), 3)
-
-
-``foldl()`` is roughly equivalent to the following recursive function::
-
-    def foldl(func, start, seq):
-        if len(seq) == 0:
-            return start
-
-        return foldl(func, func(start, seq[0]), seq[1:])
-
-Speaking of equivalence, the above ``foldl`` call can be expressed in terms of
-the built-in ``reduce`` like so::
-
-    reduce(f, [1, 2, 3], 0)
-
-
-We can use ``foldl()``, ``operator.concat()`` and ``partial()`` to write a
-cleaner, more aesthetically-pleasing version of Python's ``"".join(...)``
-idiom::
-
-    from functional import foldl, partial from operator import concat
-
-    join = partial(foldl, concat, "")
-
-
 Revision History and Acknowledgements
 =====================================
 
@@ -1296,9 +1169,10 @@
 
 Mertz also wrote a 3-part series of articles on functional programming
 for IBM's DeveloperWorks site; see
-`part 1 <http://www-128.ibm.com/developerworks/library/l-prog.html>`__,
-`part 2 <http://www-128.ibm.com/developerworks/library/l-prog2.html>`__, and
-`part 3 <http://www-128.ibm.com/developerworks/linux/library/l-prog3.html>`__,
+
+`part 1 <http://www.ibm.com/developerworks/linux/library/l-prog/index.html>`__,
+`part 2 <http://www.ibm.com/developerworks/linux/library/l-prog2/index.html>`__, and
+`part 3 <http://www.ibm.com/developerworks/linux/library/l-prog3/index.html>`__,
 
 
 Python documentation

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list