#24828 closed enhancement (fixed)

Length-checking iterator

Reported by: jdemeyer Owned by:
Priority: major Milestone: sage-8.2
Component: misc Keywords:
Cc: tscrim, embray Merged in:
Authors: Jeroen Demeyer Reviewers: Vincent Delecroix
Report Upstream: N/A Work issues:
Branch: 0201afa (Commits) Commit: 0201afab458427dd5368283ea5edefd58da33826
Dependencies: Stopgaps:

Description

Implement a wrapper for an iterator to verify that it has a specified length.

I need this for #24742 but it seems generally useful.

Change History (11)

comment:1 Changed 22 months ago by jdemeyer

  • Branch set to u/jdemeyer/length_checking_iterator

comment:2 Changed 22 months ago by jdemeyer

  • Commit set to 0201afab458427dd5368283ea5edefd58da33826
  • Status changed from new to needs_review

New commits:

0201afaImplement length-checking iterator

comment:3 follow-up: Changed 22 months ago by vdelecroix

Why did you implement the check method on its own? Why the code not directly into __next__?

comment:4 in reply to: ↑ 3 ; follow-up: Changed 22 months ago by jdemeyer

Replying to vdelecroix:

Why did you implement the check method on its own? Why the code not directly into __next__?

Because I need to call it twice, also from __init__. If you're worried about efficiency, that shouldn't be a problem because it's inlined.

comment:5 in reply to: ↑ 4 ; follow-ups: Changed 22 months ago by vdelecroix

Replying to jdemeyer:

Replying to vdelecroix:

Why did you implement the check method on its own? Why the code not directly into __next__?

Because I need to call it twice, also from __init__. If you're worried about efficiency, that shouldn't be a problem because it's inlined.

Not efficiency at all (this class is not intended to be efficient anyway). Just readability.

comment:6 in reply to: ↑ 5 Changed 22 months ago by jdemeyer

Replying to vdelecroix:

this class is not intended to be efficient anyway

Of course it is!

comment:7 in reply to: ↑ 5 Changed 21 months ago by jdemeyer

Replying to vdelecroix:

Just readability.

I would actually argue that separating concerns (iteration vs. checking) improves readability...

comment:8 Changed 21 months ago by jdemeyer

  • Cc tscrim embray added

comment:9 Changed 21 months ago by vdelecroix

  • Reviewers set to Vincent Delecroix
  • Status changed from needs_review to positive_review

comment:10 Changed 21 months ago by embray

This is useful for dealing with some of the kinds of issues discussed in #24757. It's not a silver-bullet since it requires either a sized object (with __len__) or an otherwise specified length, but that's still useful for a lot of cases.

comment:11 Changed 21 months ago by vbraun

  • Branch changed from u/jdemeyer/length_checking_iterator to 0201afab458427dd5368283ea5edefd58da33826
  • Resolution set to fixed
  • Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.