Exemplo n.º 1
0
def _filter_map(*args, **kwargs):
    if len(args) == 3 and isinstance(args[2], Macro):
        seq = args[1]
        func = args[2]
    else:
        seq, func = prepare_map(args, kwargs)
    if seq:
        for item in seq:
            yield func(item)
Exemplo n.º 2
0
async def _filter_map(*args, **kwargs):
    if len(args) == 3 and isinstance(args[2], Macro):
        seq = args[1]
        func = args[2]
    else:
        seq, func = prepare_map(args, kwargs)
    if seq:
        async for item in asynciter(seq):
            yield await auto_await(func(item))
Exemplo n.º 3
0
def _filter_map(*args, **kwargs):
    """
    Maps an iterable's values.

    This mimics Jinja2's built-in map filter, but allows macros as callbacks.
    """
    if len(args) == 3 and isinstance(args[2], Macro):
        seq = args[1]
        func = args[2]
    else:
        seq, func = prepare_map(args, kwargs)
    if seq:
        for item in seq:
            yield func(item)
Exemplo n.º 4
0
def _filter_map(
    context: Context,
    value: Union[AsyncIterable, Iterable],
    *args: Any,
    **kwargs: Any,
):
    """
    Maps an iterable's values.

    This mimics Jinja2's built-in map filter, but allows macros as callbacks.
    """
    if value:
        if len(args) > 0 and isinstance(args[0], Macro):
            func = args[0]
        else:
            func = prepare_map(context, args, kwargs)
        for item in value:
            yield func(item)
Exemplo n.º 5
0
async def do_map(*args, **kwargs):
    seq, func = filters.prepare_map(args, kwargs)
    if seq:
        async for item in auto_aiter(seq):
            yield func(item)
Exemplo n.º 6
0
async def do_map(*args, **kwargs):
    seq, func = filters.prepare_map(args, kwargs)
    if seq:
        async for item in auto_aiter(seq):
            yield await auto_await(func(item))