Toolz: A functional standard library for Python
github.com
github.com
As long as I'm "in charge" the chances of this (or anything like it) being accepted into
Python are zero. I get a headache when I try to understand code that uses function
composition, and I end up having to laboriously rewrite it using more traditional
call notation before I move on to understanding what it actually does. Python is not
Haskell, and perhaps more importantly, Python users are not like Haskell users.
Either way, what may work out beautifully in Haskell will be like a
fish out of water in Python.
I understand that it's fun to try to sole this puzzle, but evolving Python is more than
solving puzzles. Enjoy debating the puzzle, but in the end Python will survive
without the solution.
http://stackoverflow.com/questions/1017621/why-isnt-python-v...I think the lack of some things like this, is a sort of reminder to the programmer that says, "hey you, you are writing Python. Not Haskell. Do not go that way because we don't have stuff to deal with what you may find further down that road".
Nothing ruins a language like adding a bunch of poorly thought out half baked features, that does not fit well with the rest of it...
Python has made it through years of criticism from people who misunderstand Guido's stance on FP in Python (and before that from people who disliked his stance on tail call optimization) without being obsoleted by pure FP languages.
Side note: I already had to write or copy/paste most of the function of pytoolz already once at least.
So if you have function f1 that takes a and returns b (a -> b) and a function f2 that takes b and returns c (b -> c) you can compose them into a function (a -> c) all it does is call f2(f1(a))
The great thing about toolz is its https://github.com/pytoolz/cytoolz counterpart which provides an optimized implementation of toolz. It is useful when you have a bottleneck in Python code - e.g. run several functions (functoolz.juxt), merge dictionaries (dicttooz.merge), etc. With cytoolz the code becomes prettier and faster, not only prettier, so it is easier for cytoolz to sneak in.
In [1]: data = [{'a': {'b': 1}}, {'a': {'c': 2}}]
In [2]: from toolz import merge, merge_with
In [3]: merge_with(merge, data) Out[3]: {'a': {'b': 1, 'c': 2}}
You'd have to be a bit clever to go fully recursive