An iterable is an object, such as a string or collection, that can be iterated over, yielding up its members one at a time.
Questions tagged [iterable]
1303 questions
9
votes
4 answers
Is there an equivalent in Scala to Python's more general map function?
I know that Scala's Lists have a map implementation with signature (f: (A) => B):List[B] and a foreach implementation with signature (f: (A) => Unit):Unit but I'm looking for something that accepts multiple iterables the same way that the Python map…

wheaties
- 35,646
- 15
- 94
- 131
8
votes
2 answers
What AsyncGenerator TypeScript type yields a Promise?
I'm trying to assign a return type to the function below:
async function *sleepyNumbers() { // what TypeScript type is this?
let n = 0;
while (true) {
yield new Promise(resolve => resolve(n++));
await new Promise(resolve =>…

Dan Dascalescu
- 143,271
- 52
- 317
- 404
8
votes
1 answer
What Dart's List's "some" method is called? Method checking if at least one element passes a test
On JavaScript arrays, there is the some method:
The some() method tests whether at least one element in the array passes the test implemented by the provided function. It returns a Boolean value.
I think there must be a similar method on the Dart…

Vince Varga
- 6,101
- 6
- 43
- 60
8
votes
3 answers
Why do so many methods use Collection rather than Iterable?
With C# I grew to love the IEnumerable interface. There are a lot of cases where that's all you want to give out and take in. In addition it's useful in the .Net library. You have for example a constructor on the List class which takes an…

Svish
- 152,914
- 173
- 462
- 620
8
votes
1 answer
typescript Symbol.iterator
I'm trying to create a custom iterable.
here is a simplified example of my code:
class SortedArray {
*[Symbol.iterator]() {
yield 1;
yield 2;
yield 3;
return 4;
}
}
const testingIterables = new…

Yariv Katz
- 1,353
- 1
- 17
- 24
8
votes
3 answers
java: design pattern for paged results
So there's Iterable and Iterator and List. What do you use if you are trying to provide an interface to other Java code, in order to encapsulate functionality provided by a remote service that returns results in "pages"?
As an example, consider a…

Jason S
- 184,598
- 164
- 608
- 970
8
votes
2 answers
Can HTMLCollections be iterated with for...of (Symbol.iterator)?
DOM4 makes NodeLists iterable:
interface NodeList {
getter Node? item(unsigned long index);
readonly attribute unsigned long length;
iterable;
};
According to WebIDL, this means
Objects implementing an interface that is declared to be…

Oriol
- 274,082
- 63
- 437
- 513
8
votes
9 answers
Finding groups of increasing numbers in a list
The aim is to find groups of increasing/monotonic numbers given a list of integers. Each item in the resulting group must be of a +1 increment from the previous item
Given an input:
x = [7, 8, 9, 10, 6, 0, 1, 2, 3, 4, 5]
I need to find groups of…

alvas
- 115,346
- 109
- 446
- 738
8
votes
1 answer
C++ template operator not found as match
I'm trying to create a general operator<< for std::ostream and any Iterable type.
This is the code:
template class Iterable> inline std::ostream& operator<<(std::ostream& s,const Iterable& iter){
s << "[ ";
bool…

tly
- 1,202
- 14
- 17
8
votes
4 answers
The Iterator interface
I have a University assignement that requires me to implement an inner class which implements the Iterator interface. The iterator works on a single-linked list superclass.
Currently my inner class looks like this:
private class ListIterator…

Henrik Hillestad Løvold
- 1,213
- 4
- 20
- 46
8
votes
3 answers
Reducing Iterable[Either[A,B]] to Either[A, Iterable[B]]
I need to reduce an Iterable[Either[Throwable, String]] to an Either[Throwable, Iterable[String]]. I don't know if this operation is pretty common or not, haven't found nothing on the Iterable trait. So I have written this function:
def reduce[A,…

Filippo De Luca
- 704
- 5
- 21
7
votes
2 answers
Python: check if an object is NOT an "array-type"
I'm looking for a way to test if an object is not of a "list-ish" type, that is - not only that the object is not iterable (e.g. - you can also run iter on a string, or on a simple object that implements iter) but that the object is not in the list…

amito
- 435
- 1
- 5
- 20
7
votes
5 answers
Convert Any Iterable to Array in Python
This just has to be a dupe, but I just didn't find any existing instance of this question...
What is the easiest way to convert any iterable to an array in Python (ideally, without importing anything)?
Note: Ideally, if the input is an array then it…

user541686
- 205,094
- 128
- 528
- 886
7
votes
0 answers
How does collections.Iterable work with isinstance()?
I was wondering why the isinstance function works with collections.Iterable for checking whether the object is iterable, if it isn't a subclass of Iterable.
If we have two classes:
class first_class(object):
pass
class second_class(object):
…

Kuzenbo
- 229
- 4
- 9
7
votes
2 answers
deep copy nested iterable (or improved itertools.tee for iterable of iterables)
Preface
I have a test where I'm working with nested iterables (by nested iterable I mean iterable with only iterables as elements).
As a test cascade consider
from itertools import tee
from typing import (Any,
Iterable)
def…

Azat Ibrakov
- 9,998
- 9
- 38
- 50