Example #1
0
def merge(*maps):
    """
    Returns a dict that consists of the rest of the dict conj-ed onto
    the first. If a key occurs in more than one dict, the mapping from
    the latter (left-to-right) will be the mapping in the result.
    """
    return reduce(partial(pairwise_merge, lambda x, y: y), maps, {})
Example #2
0
def merge_with(f, *maps):
    """
    Returns a dict that consists of the rest of the maps conj-ed onto
    the first. If a key occurs in more than one dict, the mapping(s)
    from the latter (left-to-right) will be combined with the mapping in
    the result by calling (f val-in-result val-in-latter).
    """
    return reduce(partial(pairwise_merge, f), maps, {})
Example #3
0
 def __init__(self, f, *args):
     self.__computation = partial(f, *args)
     self.realised = False
Example #4
0
def test_map_vals():
    assert map_vals({}, partial(plus, 1)) == {}
    assert map_vals({"a": 1}, partial(plus, 1)) == {"a": 2}