示例#1
0
async def test_filter_curried_async_sync_mix():
    assert (await functional_generic.pipe(
        [1, 2, 3, 4],
        functional_generic.curried_filter(_is_even_async),
        functional_generic.curried_map(functional.add(10)),
        tuple,
    ) == (12, 14))
示例#2
0
def test_apply_spec():
    assert (functional_generic.apply_spec(
        {
            "identity": functional.identity,
            "increment": functional.add(1)
        }, )(1) == {
            "identity": 1,
            "increment": 2
        })
示例#3
0
async def test_apply_spec_async_recursive():
    async def async_identity(x):
        await asyncio.sleep(0.01)
        return x

    f = functional_generic.apply_spec(
        {
            "identity": {
                "nested": async_identity
            },
            "increment": functional.add(1)
        }, )
    assert await f(1) == {"identity": {"nested": 1}, "increment": 2}
示例#4
0
async def test_apply_spec_async():
    async def async_identity(x):
        await asyncio.sleep(0.01)
        return x

    assert (await functional_generic.apply_spec(
        {
            "identity": async_identity,
            "increment": functional.add(1)
        }, )(1) == {
            "identity": 1,
            "increment": 2
        })
示例#5
0
def test_add():
    assert functional.add(1)(2) == 3
    assert functional.add(["c"])(["a", "b"]) == ["a", "b", "c"]
示例#6
0
def test_juxt():
    assert functional_generic.juxt(functional.identity,
                                   functional.add(1))(3) == (3, 4)
示例#7
0
def test_apply():
    assert apply_utils.apply(1)(functional.add(2)) == 3