Skip to content

Migrate Iter.filter_star to the Rust iterator backend#26

Closed
Copilot wants to merge 3 commits into
masterfrom
copilot/migrate-iter-filter-star
Closed

Migrate Iter.filter_star to the Rust iterator backend#26
Copilot wants to merge 3 commits into
masterfrom
copilot/migrate-iter-filter-star

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 30, 2026

Iter.filter_star was still using the Python fallback while adjacent iterator adapters had already moved to the Rust-backed _tools module. This change migrates filter_star to the same backend without changing its external behavior, including support for unpacking non-tuple iterable elements.

  • Rust iterator adapter

    • Adds _tools.FilterStar in rust/src/tools.rs
    • Unpacks each yielded element into positional arguments, evaluates the predicate, and yields the original item when it passes
    • Preserves the existing runtime contract for any iterable element, not just tuple
  • Python API wiring

    • Switches Iter.filter_star() to delegate to tls.FilterStar(...)
    • Removes filter_star from the remaining Python-side Rust migration TODO list
  • Typing surface

    • Adds the internal _tools.pyi stub for FilterStar
    • Extends Iter.filter_star overloads with a generic iterable fallback so strict typing matches the runtime behavior
  • Regression coverage

    • Adds focused coverage for filter_star with non-tuple iterable elements to guard the preserved unpacking semantics
from pyochain import Iter

data = ([0, "a"], [1, "b"], [2, "c"])

result = Iter(data).filter_star(lambda index, _item: index % 2 == 0).collect()
# Seq([0, "a"], [2, "c"])

Copilot AI linked an issue May 30, 2026 that may be closed by this pull request
Copilot AI and others added 2 commits May 30, 2026 15:18
Co-authored-by: OutSquareCapital <166045166+OutSquareCapital@users.noreply.github.com>
Co-authored-by: OutSquareCapital <166045166+OutSquareCapital@users.noreply.github.com>
Copilot AI changed the title [WIP] Migrate Iter::filter_star Migrate Iter.filter_star to the Rust iterator backend May 30, 2026
Copilot AI requested a review from OutSquareCapital May 30, 2026 15:26
Comment thread src/pyochain/_iter.py
func: Callable[[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10], bool],
) -> Iter[tuple[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10]]: ...
@overload
def filter_star[U: AnyIter](self: Iter[U], func: Callable[..., bool]) -> Iter[U]: ...
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this needed?

Comment thread src/pyochain/_tools.pyi
@override
def __next__(self) -> tuple[T, ...]: ...

class FilterStar[T: Iterable[Any]](Iterator[T]):
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this work with the overloads at the call site?

Comment thread tests/test_filter_star.py
from pyochain import Iter, Seq


def test_filter_star_preserves_non_tuple_iterables() -> None:
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

trivial tests like this should be documented in the docstring.

Comment thread rust/src/tools.rs
slf
}

fn __next__(slf: PyRefMut<'_, Self>) -> PyResult<Option<Py<PyAny>>> {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So at each iteration we copy each element in a Vec to unbind it?? this must be slow as fuck, as this been measured?

I didn't see any benchmark result by the way.

I'm not sure we want to support non-tuples.

We already don't for the for_each_* methods anyway.

Copilot AI requested a review from OutSquareCapital May 30, 2026 15:38
@OutSquareCapital OutSquareCapital deleted the copilot/migrate-iter-filter-star branch May 31, 2026 12:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Migrate Iter::filter_star

2 participants