Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
johnmcclean committed Sep 11, 2015
1 parent a1eadfd commit 66e67db
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ default T mapReduce(Stream toReduce){
return reduce(mapToType(toReduce));
}
default T reduce(Stream<T> toReduce){
return toReduce.reduce(reducer()).orElse(zero());
return toReduce.reduce(zero(),reducer());
}

public static <T> Monoid<T> of(T zero, Function<T,Function<T,T>> combiner,Function<?,T> mapToType){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,19 @@ public C next() {
C list = factory.get();
if(value!=UNSET)
list.add(value);
while(it.hasNext() && predicate.test(value=it.next())){
list.add(value);
value=(T)UNSET;
}
T value;

label: while(it.hasNext()) {
value=it.next();
list.add(value);

if(!predicate.test(value)){
value=(T)UNSET;
break label;
}
value=(T)UNSET;

}
return list;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void batchWhile(){
.size(),equalTo(2));
assertThat(SequenceM.of(1,2,3,4,5,6)
.batchWhile(i->i%3!=0)
.toList(),equalTo(Arrays.asList(1,2,3)));
.toList(),equalTo(Arrays.asList(Arrays.asList(1,2,3),Arrays.asList(4,5,6))));
}
@Test
public void batchUntilCollection(){
Expand All @@ -63,7 +63,7 @@ public void batchWhileCollection(){
.toList().size(),equalTo(2));
assertThat(SequenceM.of(1,2,3,4,5,6)
.batchWhile(i->i%3!=0,()->new ArrayList<>())
.toList(),equalTo(Arrays.asList(1,2,3)));
.toList(),equalTo(Arrays.asList(Arrays.asList(1,2,3),Arrays.asList(4,5,6))));
}
@Test
public void batchByTime2(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void flatMapCollection(){
}
@Test
public void flatMapCollectionAnyM(){
assertThat( anyM(Optional.of(20)).flatMapCollection(i->Arrays.asList(1,2,i) ).asSequence().toList(),equalTo(Arrays.asList(1,2,20)));
assertThat( anyM(Optional.of(20)).flatMapCollection(i->Arrays.asList(1,2,i) ).toSequence().toList(),equalTo(Arrays.asList(1,2,20)));
}
@Test
public void flatMapToSeq(){
Expand Down

0 comments on commit 66e67db

Please sign in to comment.