Skip to content

Commit

Permalink
curried.merge_with can accept a list of dicts. Fixes #24
Browse files Browse the repository at this point in the history
Regression test included.  Should be backported to toolz.
  • Loading branch information
eriknw committed May 3, 2014
1 parent 6b2b087 commit 632cfd0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions cytoolz/curried_exceptions.pyx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#cython: embedsignature=True
from cpython.dict cimport PyDict_Check
from .dicttoolz cimport c_merge_with

__all__ = ['merge_with']
Expand All @@ -22,4 +23,7 @@ def merge_with(func, *dicts):
"""
if len(dicts) == 0:
raise TypeError
if len(dicts) == 1 and not PyDict_Check(dicts[0]):
dicts = dicts[0]

return c_merge_with(func, dicts)
5 changes: 5 additions & 0 deletions cytoolz/tests/test_curried.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ def test_merge_with():
assert merge_with(sum)({1: 1}, {1: 2}) == {1: 3}


# XXX: backport to toolz
def test_merge_with_list():
assert merge_with(sum, [{'a': 1}, {'a': 2}]) == {'a': 3}


def test_sorted():
assert sorted(key=second)([(1, 2), (2, 1)]) == [(2, 1), (1, 2)]

Expand Down

0 comments on commit 632cfd0

Please sign in to comment.