Ordering and grouping¶
Ordering¶
order_by is stable, and then_by adds a tie-breaker:
by_length = flp.it(words).order_by(len)
# order_by is stable: equal keys keep their original order.
assert by_length.to_list() == ["fig", "pear", "kiwi", "apple"]
# then_by adds a secondary key; it does not replace the primary one.
assert by_length.then_by(lambda w: w).to_list() == ["fig", "kiwi", "pear", "apple"]
Grouping¶
group_by yields groups with a key. Each group is itself a query over its elements: