iterable Questions

4

Solved

I've got a set of rows in a database, and I'd like to provide an interface to spin through them like this: def findAll: Iterable[MyObject] Where we don't require having all the instances in memo...
Ingvar asked 20/1, 2010 at 15:47

25

Solved

Is there a method like isiterable? The only solution I have found so far is to call hasattr(myObj, '__iter__') But I am not sure how fool-proof this is.
Mirtamirth asked 23/12, 2009 at 12:13

3

Solved

Help! I'm learning to love Javascript after programming in C# for quite a while but I'm stuck learning to love the iterable protocol! Why did Javascript adopt a protocol that requires creating a n...
Hundredpercenter asked 22/12, 2018 at 9:52

5

I am not able to find a simple way how to initialize a Pydantic object from field values given by position (for example in a list instead of a dictionary) so I have written class method positional_...
Teutonism asked 25/10, 2021 at 16:50

8

Solved

I'm trying to find an elegant way to find the max value in a two-dimensional array. for example for this array: [0, 0, 1, 0, 0, 1] [0, 1, 0, 2, 0, 0][0, 0, 2, 0, 0, 1][0, 1, 0, 3, 0, 0][0, 0, 0, 0...
Oliverolivera asked 20/11, 2016 at 8:11

2

Solved

In PHP 7.1 there is a new iterable psudo-type which abstracts arrays and Traversable objects. Suppose that in my code I have a class like the following: class Foo { private $iterable; public f...
Choli asked 24/4, 2017 at 16:46

3

I want to map a list of Objects to an Object that contains a list: public class Group { private List<Person> people; } public class Person { private String name; } I tried creating a ma...
Stark asked 25/3, 2019 at 15:28

8

Solved

Suppose I have an arbitrary iterable - for example, a generator that iterates over lines of a file and yields the ones matching a regex. How can I count the number of items in that iterable, suppos...
Unused asked 21/3, 2011 at 22:35

4

Solved

and both of them get a Consumer as parameter. so if Java 8, is meant to avoid confusions, like it has done in Time API, why has it added a new confusion? or am I missing some point?
Prolepsis asked 26/2, 2017 at 7:26

15

Solved

I am new in Java and I'm really confused with iterator and iterable. Can anyone explain to me and give some examples?
Roney asked 28/7, 2011 at 17:35

7

What's the shortest way to get first item of OrderedDict in Python 3? My best: list(ordered_dict.items())[0] Quite long and ugly. I can think of: next(iter(ordered_dict.items())) # Fixed, th...
Lobation asked 11/1, 2014 at 13:25

21

Solved

In my application I use 3rd party library (Spring Data for MongoDB to be exact). Methods of this library return Iterable<T>, while the rest of my code expects Collection<T>. Is there an...
Gillum asked 20/6, 2011 at 19:56

16

Solved

Why isn't is possible to use objects in for of loops? Or is this a browser bug? This code doesn't work in Chrome 42, saying undefined is not a function: test = { first: "one"} for(var item of tes...
Biform asked 27/4, 2015 at 0:13

4

Solved

I have been going over the tqdm docs, but no matter where I look, I cannot find a method by which to extract the time passed and estimated time remaining fields (basically the center of the progres...
Altruism asked 19/6, 2019 at 23:45

4

Solved

Python list comprehension is really simple: >>> l = [x for x in range(1, 10) if x % 2 == 0] >>> [2, 4, 6, 8] Does Rust have an equivalent syntax like: let vector = vec![x for...
Wages asked 24/7, 2017 at 14:18

6

Solved

In Java 5 and above you have the foreach loop, which works magically on anything that implements Iterable: for (Object o : list) { doStuff(o); } However, Enumerable still does not implement Ite...
Esposito asked 26/8, 2008 at 1:57

3

Solved

I've already looked at this post about iterable python errors: "Can only iterable" Python error But that was about the error "cannot assign an iterable". My question is why is python te...
Laryngology asked 21/8, 2015 at 15:29

5

Solved

I have a string sample = "http://www.stackoverflow.com" I want convert this string to a set final = {"http://www.stackoverflow.com"} I tried the following code: final = set(sample) But i ...
Deming asked 28/11, 2014 at 16:10

6

Solved

Which one of these is considered the more pythonic, taking into account scalability and readability? Using enumerate: group = ['A','B','C'] tag = ['a','b','c'] for idx, x in enumerate(group): pr...
Soni asked 27/11, 2015 at 10:52

1

Solved

I need to match cases where the input is iterable. Here's what I tried: from typing import Iterable def detector(x: Iterable | int | float | None) -> bool: match x: case Iterable(): print('I...
Involucrum asked 1/3, 2022 at 19:41

1

Solved

First time trying typescript. I have an object that looks like interface Job { //... some data priority: number } and I want to return the highest priority from a Set of Jobs (note: not the Job i...
Knotts asked 22/2, 2022 at 19:35

14

Solved

If I have a collection, such as Collection<String> strs, how can I get the first item out? I could just call an Iterator, take its first next(), then throw the Iterator away. Is there a less ...
Consecutive asked 4/11, 2009 at 2:22

1

I got stuck, trying to implement combine logic for a list of mixed iterables, i.e. I have a list of Iterable + Iterator + AsyncIterable + AsyncIterator, for which I'm trying to combine them togethe...
Cuculiform asked 19/12, 2021 at 9:35

4

Something similar to question Convert ES6 Iterable to Array. But I only want first N items. Is there any built-in for me to do so? Or how can I achieve this more elegantly? let N = 100; function *...
Jonathonjonati asked 29/11, 2017 at 1:54

2

Solved

I want to get the last element of a lazy but finite Seq in Raku, e.g.: my $s = lazy gather for ^10 { take $_ }; The following don't work: say $s[* - 1]; say $s.tail; These ones work but don't see...
Pneumonic asked 4/12, 2021 at 17:50

© 2022 - 2024 — McMap. All rights reserved.