FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Bug in AdvancerList in conjunction with reduce operation without Identity by dpoeira91 · Pull Request #7 · tinyield/jayield · GitHub

Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .java  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
7 changes: 6 additions & 1 deletion src/main/java/org/jayield/advs/AdvancerList.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,17 @@
public class AdvancerList<U> implements Advancer<U> {
private final List<U> data;
private final Iterator<U> current;
private int index;

public AdvancerList(List<U> data) {
this.data = data;
this.current = data.iterator();
index = 0;
}

@Override
public U next() {
index++;
return current.next();
}

Expand All @@ -43,6 +46,8 @@ public boolean hasNext() {

@Override
public void traverse(Yield<? super U> yield) {
data.forEach(yield::ret);
for (int i = index; i < data.size(); i++) {
yield.ret(data.get(i));
}
}
}
24 changes: 24 additions & 0 deletions src/test/java/org/jayield/QueryTraverseTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.jayield;

import static java.util.Arrays.asList;
import static org.jayield.Query.fromList;
import static org.jayield.Query.fromStream;
import static org.jayield.Query.iterate;
import static org.jayield.Query.of;
Expand Down Expand Up @@ -293,6 +294,29 @@ public void testReduce() {
assertEquals(actual, expected);
}

@Test
public void testFlatMapAndReduce() {
List<Query<String>> input = new ArrayList<>();
input.add(Query.of("a"));
input.add(Query.of("b"));
input.add(Query.of("c"));
String expected = "abc";
String actual = fromList(input).flatMap(s -> s).reduce((p, c) -> p + c).orElseThrow();
assertEquals(actual, expected);
}


@Test
public void testFromListFlatMapAndReduce() {
List<Query<String>> input = new ArrayList<>();
input.add(fromList(List.of("a")));
input.add(fromList(List.of("b")));
input.add(fromList(List.of("c")));
String expected = "abc";
String actual = fromList(input).flatMap(s -> s).reduce((p, c) -> p + c).orElseThrow();
assertEquals(actual, expected);
}

@Test
public void testReduceOnEmpty() {
String[] input = {};
Expand Down

Back | FazBrowse Home | New Git URL