import itertools


def bind_dict_to_arg(mapper, new_binds):
    """Return a generator that converts new_binds to valid container-runner bind
    arguments.

    Args:
        mapper (callable): Function that returns a key, val argument pair when called
            with mapper(source, dest). For example, see docker.volume_bind_args
        new_binds (dict): binds specified in source:destination format

    Returns:
        generator: returns a [key, val] argument pair for each key in new_binds

    """
    # concatenated list of tuples - surprisingly ugly for python but efficient
    return itertools.chain.from_iterable(
        (mapper(source, dest) for source, dest in new_binds.items())
    )