Ejemplo n.º 1
0
 def xpartially_applied(*func_args, **func_kwargs):
     if any_x:
         if not func_args:
             raise ValueError('Function "%s" partially applied with an '
                 'X placeholder but called with no positional arguments.'
                 % get_name(func))
         first = func_args[0]
         rest = func_args[1:]
         args = tuple(use(x, first) for x in xargs) + rest
         kwargs = dict((k, use(x, first)) for k, x in dict_items(xkwargs))
         kwargs.update(func_kwargs)
     else:
         args = xargs + func_args
         kwargs = dict(xkwargs, **func_kwargs)
     return func(*args, **kwargs)
Ejemplo n.º 2
0
 def xpartially_applied(*func_args, **func_kwargs):
     if any_x:
         if not func_args:
             raise ValueError('Function "%s" partially applied with an '
                 'X placeholder but called with no positional arguments.'
                 % get_name(func))
         first = func_args[0]
         rest = func_args[1:]
         args = tuple(use(x, first) for x in xargs) + rest
         kwargs = dict((k, use(x, first)) for k, x in dict_items(xkwargs))
         kwargs.update(func_kwargs)
     else:
         args = xargs + func_args
         kwargs = dict(xkwargs, **func_kwargs)
     return func(*args, **kwargs)
Ejemplo n.º 3
0
    def pipe_util_wrapper(function, *args, **kwargs):
        if isinstance(function, XObject):
            function = ~function

        original_function = function

        if args or kwargs:
            function = xpartial(function, *args, **kwargs)

        name = lambda: '%s(%s)' % (get_name(func), ', '.join(
            filter(None, (get_name(original_function), repr_args(*args, **kwargs)))))

        f = func(function)

        result = pipe | set_name(name, f)

        # if the util defines an 'attrs' mapping, copy it as attributes
        # to the result
        attrs = getattr(f, 'attrs', {})
        for k, v in dict_items(attrs):
            setattr(result, k, v)

        return result
Ejemplo n.º 4
0
 def _group_by(seq):
     result = {}
     for item in seq:
         result.setdefault(function(item), []).append(item)
     return dict_items(result)
Ejemplo n.º 5
0
def repr_args(*args, **kwargs):
    return ', '.join(chain(
        map('{0!r}'.format, args),
        map('{0[0]}={0[1]!r}'.format, dict_items(kwargs))))
Ejemplo n.º 6
0
def repr_args(*args, **kwargs):
    return ', '.join(
        chain(map('{0!r}'.format, args),
              map('{0[0]}={0[1]!r}'.format, dict_items(kwargs))))
Ejemplo n.º 7
0
 def _group_by(seq):
     result = {}
     for item in seq:
         result.setdefault(function(item), []).append(item)
     return dict_items(result)
Ejemplo n.º 8
0
def select_builder(definition):
    for cls, builder in dict_items(builders):
        if isinstance(definition, cls):
            return builder
Ejemplo n.º 9
0
def DictBuilder(definition):
    return lambda x: dict((ds_item(key_def, x), ds_item(val_def, x))
                          for key_def, val_def in dict_items(definition))
Ejemplo n.º 10
0
def select_builder(definition):
    for cls, builder in dict_items(builders):
        if isinstance(definition, cls):
            return builder
Ejemplo n.º 11
0
def DictBuilder(definition):
    return lambda x: dict(
        (ds_item(key_def, x), ds_item(val_def, x))
        for key_def, val_def in dict_items(definition))