asyncdef / aitertools

Async versions of the Python itertools features.
Apache License 2.0
20 stars 4 forks source link

groupby is bugged #6

Closed purpleP closed 6 years ago

purpleP commented 7 years ago
async def test_groupby_lazy():
    groups = aitertools.groupby((1, 2, 3, 1, 2, 3), key=lambda x: x)
    g = await aitertools.atuple(groups)
    assert 1 == g[0][0]
    assert (1, 1) == await aitertools.atuple(g[0][1])
    # k1, g1 = await aitertools.anext(groups)
    # assert 1 == k1
    # k2, g2 = await aitertools.anext(groups)
    # assert 2 == k2
    # k3, g3 = await aitertools.anext(groups)
    # assert 3 == k3
    # assert 1 == await aitertools.anext(g1)
    # assert 2 == await aitertools.anext(g2)

It will return 1, 3 instead of (1, 1) in the second assert. I'm not sure what you core is trying to do, but it seems that it doesn't try storing groups in any way.

I will probably fix this myself, but if you would do this first I suggest you to look at how I've implemented fully lazy (in a sence that it wouldn't get next item, until it really have to) groupby iterable here