Word for a non-iterator iterable?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Leif K-Brooks

    #1

    Word for a non-iterator iterable?

    Is there a word for an iterable object which isn't also an iterator, and
    therefor can be iterated over multiple times without being exhausted?
    "Sequence" is close, but a non-iterator iterable could technically
    provide an __iter__ method without implementing the sequence protocol,
    so it's not quite right.
  • vincent wehren

    #2
    Re: Word for a non-iterator iterable?

    Leif K-Brooks wrote:[color=blue]
    > Is there a word for an iterable object which isn't also an iterator, and
    > therefor can be iterated over multiple times without being exhausted?
    > "Sequence" is close, but a non-iterator iterable could technically
    > provide an __iter__ method without implementing the sequence protocol,
    > so it's not quite right.[/color]

    How about 'reiterable'?

    --
    Vincent Wehren

    Comment

    • Alex Martelli

      #3
      Re: Word for a non-iterator iterable?

      Leif K-Brooks <eurleif@ecritt ers.biz> wrote:
      [color=blue]
      > Is there a word for an iterable object which isn't also an iterator, and
      > therefor can be iterated over multiple times without being exhausted?
      > "Sequence" is close, but a non-iterator iterable could technically
      > provide an __iter__ method without implementing the sequence protocol,
      > so it's not quite right.[/color]

      Not just ``technically'' -- a dict is a good and very common example of
      just such a "non-iterator, non-sequence iterable".

      As you're focusing on "can be iterated over multiple-times", I like
      "re-iterable"; it centers on what you can DO with the object, rather
      than quibbling what it ISN'T;-)


      Alex

      Comment

      • Terry Reedy

        #4
        Re: Word for a non-iterator iterable?


        "vincent wehren" <vincent@visual trans.de> wrote in message
        news:cu4kjo$d8s $1@news2.tilbu1 .nb.home.nl...[color=blue]
        > Leif K-Brooks wrote:[color=green]
        >> Is there a word for an iterable object which isn't also an iterator, and
        >> therefor can be iterated over multiple times without being exhausted?[/color][/color]

        The 'therefor' above is a non sequitor. A non-iterator iterable can also
        be non-reiterable.
        [color=blue]
        > How about 'reiterable'?[/color]

        I agree. Reiterability is essential for some algorithms, while I am hard
        put to think of a situation in which non-iterator-ness, by itself, is.

        Terry J. Reedy




        Comment

        • Oren Tirosh

          #5
          Re: Word for a non-iterator iterable?

          Leif K-Brooks <eurleif@ecritt ers.biz> wrote in message news:<36lu1cF51 6qtdU1@individu al.net>...[color=blue]
          > Is there a word for an iterable object which isn't also an iterator, and
          > therefor can be iterated over multiple times without being exhausted?
          > "Sequence" is close, but a non-iterator iterable could technically
          > provide an __iter__ method without implementing the sequence protocol,
          > so it's not quite right.[/color]

          "reiterable ". I think I was the first to use this word on
          comp.lang.pytho n.

          If you have code that requires this property might want to use this
          function:

          ..def reiter(x):
          .. i = iter(x)
          .. if i is x:
          .. raise TypeError, "Object is not re-iterable"
          .. return i

          example:

          ..for outer in x:
          .. for inner in reiter(y):
          .. do_something_wi th(outer, inner)

          This will raise an exception when an iterator is used for y instead of
          silently failing after the first time through the outer loop and
          making it look like an empty container.

          When iter() returns a new iterator object it is a good hint but not a
          100% guarantee that the object is reiterable. For example, python 2.2
          returned a new xreadlines object for iterating over a file but it
          messed up the underlying file object's state so it still wasn't
          reiterable. But when iter() returns the same object - well, that's a
          sign that the object is definitely not reiterable.

          Oren

          Comment

          • Terry Reedy

            #6
            Re: Word for a non-iterator iterable?


            "Oren Tirosh" <oren@REMOVETHI S1.hishome.net> wrote in message
            news:cf052f0d.0 502071110.4e961 1e0@posting.goo gle.com...[color=blue]
            > But when iter() returns the same object - well, that's a
            > sign that the object is definitely not reiterable.[/color]

            Unless, of course, __iter__ resets the iteration variable to its starting
            value. But it would definitely not be simultaneously doubly iterable, as
            one would want to compute a self crossproduct. And one could object that
            such an __iter__ is not proper for an iterator (return self and do nothing
            else). So such an __iter__ should better be written, perhap as a generator
            function, to return an independent object with independently initialized
            iteration variable.

            Terry J. Reedy



            Comment

            Working...