Skip to content

Commit 8ae8c19

Browse files
committed
minor fixes
1 parent 5871bf7 commit 8ae8c19

2 files changed

Lines changed: 27 additions & 15 deletions

File tree

‎koans/src/java8/AboutLambdas.java‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
import com.sandwich.koan.Koan;
44

5+
import java.util.function.Function;
6+
import java.util.function.Predicate;
7+
58
import static com.sandwich.util.Assert.assertEquals;
69
import static com.sandwich.koan.constant.KoanConstants.__;
710

@@ -11,6 +14,8 @@ interface Caps {
1114

1215
public class AboutLambdas {
1316

17+
String fieldFoo = "Lambdas";
18+
1419
@Override
1520
public String toString() {
1621
return "CAPS";
@@ -75,5 +80,12 @@ public void methodReference() {
7580
assertEquals(capitalized, __);
7681
}
7782

83+
@Koan
84+
public void thisIsSurroundingClass() {
85+
//"this" in lambda points to surrounding class
86+
Function<String, String> foo = s -> s + this.fieldFoo + s;
87+
assertEquals(foo.apply("|"), __);
88+
}
89+
7890
}
7991

‎koans/src/java8/AboutStreams.java‎

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,44 +35,44 @@ public void max(){
3535
String longest = places.stream()
3636
.max(Comparator.comparing(cityName -> cityName.length()))
3737
.get();
38-
assertEquals(longest, "");
38+
assertEquals(longest, __);
3939
}
4040

4141
@Koan
4242
public void min(){
4343
String longest = places.stream()
4444
.max(Comparator.comparing(cityName -> cityName.length()))
4545
.get();
46-
assertEquals(longest, "");
47-
}
48-
49-
@Koan
50-
public void reduceWithoutFirstElementReturnsOptional(){
51-
Optional<String> join = places.stream()
52-
.reduce(String::concat);
53-
assertEquals(join.get(), "");
46+
assertEquals(longest, __);
5447
}
5548

5649
@Koan
5750
public void reduce(){
5851
String join = places.stream()
5952
.reduce("", String::concat);
60-
assertEquals(join, "");
53+
assertEquals(join, __);
54+
}
55+
56+
@Koan
57+
public void reduceWithoutStarterReturnsOptional(){
58+
Optional<String> join = places.stream()
59+
.reduce(String::concat);
60+
assertEquals(join.get(), __);
6161
}
6262

6363
@Koan
6464
public void join(){
6565
String join = places.stream()
6666
.reduce((accumulated, cityName) -> accumulated + "\", \"" + cityName)
6767
.get();
68-
assertEquals(join, "");
68+
assertEquals(join, __);
6969
}
7070

7171
@Koan
7272
public void reduceWithBinaryOperator(){
7373
String join = places.stream()
7474
.reduce("", String::concat);
75-
assertEquals(join, "");
75+
assertEquals(join, __);
7676
}
7777

7878
@Koan
@@ -101,12 +101,12 @@ public void parallelMapReduce(){
101101

102102
@Koan
103103
public void limitSkip(){
104-
int lengthSum_Limit_5_Skip_1 = places.stream()
104+
int lengthSum_Limit_3_Skip_1 = places.stream()
105105
.mapToInt(String::length)
106-
.limit(5)
106+
.limit(3)
107107
.skip(1)
108108
.sum();
109-
assertEquals(lengthSum_Limit_5_Skip_1, __);
109+
assertEquals(lengthSum_Limit_3_Skip_1, __);
110110
}
111111

112112
@Koan

0 commit comments

Comments
 (0)