Open bismigalis opened 10 years ago
Hi @bismigalis ,
Thanks for the suggestion. I'm sorry that you feel that merge_with
is not useful to your application. Binary operators simply aren't as popular within the Python community as they are in Clojure's, hence our decision to use reduction functions (like sum) rather than binary operators (like add). This is pretty subjective though and it's not clear that it was the right decision.
One solution would be to support variadic functions in merge_with
if the inspect
module can detect them. This is the solution proposed in https://github.com/pytoolz/toolz/pull/127
Another solution is simply to reduce your binary operator prior to using merge_with
In [1]: from operator import mod
In [2]: from toolz import curry, merge_with
In [3]: reduce = curry(reduce)
In [4]: merge_with(reduce(mod), {'a': 1}, {'a': 2})
Out[4]: {'a': 1}
I cant use binary operations with it
CLojure's version http://clojuredocs.org/clojure_core/clojure.core/merge-with does right thing
here is python version of it