iterable

Hamcrest: when iterableWithSize fails, it gives a bad message like “got: com.xxx.MyIterClass$1@1970ae0”

我的未来我决定 提交于 2019-12-13 05:43:27
问题 In hamcrest (1.3.RC2, with no JUnit dependencies) I am failing using iterableWithSize() with a SpringDataNeo4j library. I have an (extension of) an Iterator parameterized with Content like this EndResult<Content> contents = contentRepository.findAllByPropertyValue("title", "*"); where EndResult is package org.springframework.data.neo4j.conversion; public interface EndResult extends Iterable {...} and Content is a a @NodeEntity Pojo. With the help of Mark Peters I learned that I should call it

Why is scala.collection.immutable.List[Object] not GenTraversableOnce[?]

↘锁芯ラ 提交于 2019-12-13 04:16:19
问题 Simple question, and sorry if this is a stupid question as I am just beginning in scala. I am getting a type mismatch error that says: found : (AnyRef, org.apache.tinkerpop.gremlin.hadoop.structure.io.VertexWritable) => List[Object] required: ((AnyRef, org.apache.tinkerpop.gremlin.hadoop.structure.io.VertexWritable)) => scala.collection.GenTraversableOnce[?] But according to this post (I have a Scala List, how can I get a TraversableOnce?), a scala.collection.immutable.List is an Iterable and

typescript Symbol.iterator

大憨熊 提交于 2019-12-12 10:42:54
问题 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 SortedArray(); for(let item of testingIterables as any) { // i have to cast it as any or it won't compile console.log(item); } This code will run correctly on ES6 but with TypeScript it will compile and not print the iterable values. Is this a bug in TypeScript or am I missing something? Thanks 回答1: It

Issue iterating over custom writable component in reducer

橙三吉。 提交于 2019-12-12 10:24:53
问题 I am using a custom writable class as VALUEOUT in the map phase in my MR job where the class has two fields, A org.apache.hadoop.io.Text and org.apache.hadoop.io.MapWritable . In my reduce function I iterate through the values for each key and I perform two operations, 1. filter, 2. aggregate. In the filter, I have some rules to check if certain values in the MapWritable(with key as Text and value as IntWritable or DoubleWritable ) satisfy certain conditions and then I simply add them to an

“Iterable<Element> cannot be cast to List<Element>” - Isn't `List` a type of `Iterable`?

帅比萌擦擦* 提交于 2019-12-12 08:24:30
问题 I called a getElements method which returns Iterable<Element> . I did this: List<Element> elements = (List<Element>) getElements(); This generates the error: java.lang.ClassCastException: com.utesy.Element$3 cannot be cast to java.util.List I thought a List was a type of Iterable ? 回答1: Yes, List<T> extends Iterable<T> , but that doesn't mean that you can cast from any Iterable<T> to List<T> - only when the value actually refers to an instance of a type of List<T> . It's entirely possible to

How to make a class (which is not a descendant of collection) “compatible” with for-each loop?

。_饼干妹妹 提交于 2019-12-11 22:05:34
问题 NOTE : In real life situation I would use an appropriate Java collection but in this task I would like to do everything form scratch. I've done my Googling here on SO and on the rest of the web, but didn't find exactly what I was looking for. It's my understanding that for-each loop can operate on any class that implements iterable interface and at the same time this class does not have to implement iterator . Am I right here? Let say, I have the following two classes that are not explicitly

Iterator returns wrong integer values

断了今生、忘了曾经 提交于 2019-12-11 19:05:21
问题 I have to implement class Incrementer and it suppose to implement Iterable . The output should be: 1 2 3 4 5 6 7 8 9 10 1 3 5 7 9 10 9 8 7 6 5 4 3 2 1 10 9 8 7 6 5 4 3 2 1 1 2 3 4 6 8 10 1 2 3 4 5 6 7 8 6 4 2 10 9 8 7 6 5 6 7 8 9 10 I do get: 2 3 4 5 6 7 8 9 10 3 5 7 9 11 9 8 7 6 5 4 3 2 1 2 3 4 6 8 10 2 3 4 5 6 7 8 9 8 7 6 5 6 7 8 9 10 My Incrementer class looks like that: package in; import java.util.Iterator; public class Incrementer implements Iterable<Integer> { int val, step, a, b;

Iterables: Objects with iterators, or generators

佐手、 提交于 2019-12-11 10:47:02
问题 Let's assume two similar implementations of an object with a defined iterator: one iterator using generators, the other using iterables. Both of these two work with Array.from , and both of them can be iterated over. What are the differences in these two approaches, which one is preferred, and why? Is there ever a need for the lesser approach? class Foo { constructor( ...args ) { this.f = args; } [Symbol.iterator]() { let c = 0; const i = { next: () => { if ( c < this.f.length ) { return

Object is not being produced on calling [Symbol.iterator]()

谁说胖子不能爱 提交于 2019-12-11 10:16:13
问题 This is this source code: const james = { name: 'James', height: `5'10"`, weight: 185, [Symbol.iterator]:function*(){ yield Object.keys(this) ; } }; const iterator = james[Symbol.iterator](); // console.log(iterator.next().value); // 'James' console.log(iterator.next().value); // `5'10` console.log(iterator.next().value); // 185 The first call to iterator.next().value is supposed to print {"value":"James","key":"name","done":false} but it is printing {"value":["name","height","weight"],"done"

Iterator of list of list of iterables

与世无争的帅哥 提交于 2019-12-11 07:57:43
问题 I would like to iterate of a list of list of Iterables in Python3. Stated differently, I have a matrix of iterables and I would like to loop through and get at each iteration a matrix of values. More concretely, I have several files (the rows) which have multiple versions of them (the columns) and I would like at each iteration, get a tuple/matrix containing the first line of all my files and so on. So, given something like this a = [ [iter(range(1,10)), iter(range(11,20)), iter(range(21,30))