def flat_map_depth(collection, iteratee=None, depth=1): """This method is like :func:`flat_map` except that it recursively flattens the mapped results up to `depth` times. Args: collection (list|dict): Collection to iterate over. iteratee (mixed, optional): Iteratee applied per iteration. Returns: list: Flattened mapped list. Example: >>> duplicate = lambda n: [[n, n]] >>> flat_map_depth([1, 2], duplicate, 1) [[1, 1], [2, 2]] >>> flat_map_depth([1, 2], duplicate, 2) [1, 1, 2, 2] .. versionadded:: 4.0.0 """ return pyd.flatten_depth(itermap(collection, iteratee=iteratee), depth=depth)
def flat_map_depth(collection, iteratee=None, depth=1): """This method is like :func:`flat_map` except that it recursively flattens the mapped results up to `depth` times. Args: collection (list|dict): Collection to iterate over. iteratee (mixed, optional): Iteratee applied per iteration. Returns: list: Flattened mapped list. Example: >>> duplicate = lambda n: [[n, n]] >>> flat_map_depth([1, 2], duplicate, 1) [[1, 1], [2, 2]] >>> flat_map_depth([1, 2], duplicate, 2) [1, 1, 2, 2] .. versionadded:: 4.0.0 """ return pyd.flatten_depth(itermap(collection, iteratee=iteratee), depth=depth)
def test_flatten_depth(case, expected): assert _.flatten_depth(*case) == expected