import itertools


def flat_map(visitor, collection):
    """Flat map operation where returned iterables are flatted.

    Args:
        visitor: Function to apply.
        collection: The collection over which to apply the function.
    Returns:
        Flattened results of applying visitor to the collection.
    """
    return itertools.chain.from_iterable(
        map(visitor, collection)
    )