def test_get_many_flat(): from liquidata import pipe, flat, get ds = (dict(a=1, b=9), dict(a=0, b=8), dict(a=3, b=7)) data = [Namespace(**d) for d in ds] net = pipe(get.a.b * flat(lambda a, b: a * [b])) assert net(data) == [9, 7, 7, 7]
def test_get_single_flat(): from liquidata import pipe, flat, get ds = (dict(a=1, b=2), dict(a=0, b=3), dict(a=3, b=1)) data = [Namespace(**d) for d in ds] net = pipe(get.a, flat(lambda n: n * [n])) assert net(data) == [1, 3, 3, 3]
def test_star_flat(): from liquidata import pipe, get, star, flat data = namespace_source() got = pipe(get.a.b, star(flat(lambda a, b: (a, b))))(data) expected = list(it.chain(*((ns.a, ns.b) for ns in data))) assert got == expected
def test_pipe_as_safe_function_on_flat(): from liquidata import pipe, flat, Many f = range pipe_fn = pipe(flat(f)).fn() assert pipe_fn(3) == Many((0, 1, 2)) assert pipe_fn(5) == Many((0, 1, 2, 3, 4))
def test_pipe_as_function_on_flat(): from liquidata import pipe, flat f = range pipe_fn = pipe(flat(f)).fn(tuple) assert pipe_fn(3) == (0, 1, 2) assert pipe_fn(5) == (0, 1, 2, 3, 4)
def test_flat(): from liquidata import pipe, flat data = range(4) f = range assert pipe(flat(f))(data) == list(it.chain(*map(f, data)))