All contributions

Suor/funcy

funcy

A collection of practical functional tools for Python, including helpers for sequences, collections and iterators.

Language
Python
GitHub stars
3,507
Merged changes
1

What we changed

partition and chunks with a step larger than the part size now give the same parts for an iterator as for a list: the right length and the right items.

What this work shows

  • Python iterators and itertools.islice
  • Sliding window edge cases
  • Tests comparing two implementations
What was broken

An iterator gave different parts than a list

partition(2, 3, ...) on a list gave [[0, 1], [3, 4], [6, 7]], but on an iterator over the same data it gave [[0, 1], [2, 3, 4], [5, 6, 7], [8, 9]]. In _cut_iter the sliding window only worked when the step was not larger than the part size, and a larger step pulled in too many items.

How we fixed it

Skipping the gap between parts

For a step smaller than the part size the sliding window stays, and otherwise _cut_iter discards the step - n items in the gap and takes n fresh ones. Tests compare partition and chunks on an iterator and on a list.

#177

Merged change

1 10 September 2026

What it taught us

When a function has separate paths for lists and for iterators, we compare both paths on the same data. That is how edge case bugs surface that no test had touched before.

More about this technology: Python

Other projects we write code for

Describe your project.

A free quote comes back within an hour during working hours.