Skip to content

Commit 02e350b

Browse files
evanjbowlingjnape
authored andcommitted
Updating README examples
1 parent cee0bf6 commit 02e350b

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

README.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -75,22 +75,22 @@ compile group: 'com.jnape.palatable', name: 'lambda', version: '4.0.0'
7575

7676
First, the obligatory `map`/`filter`/`reduce` example:
7777
```Java
78-
Integer sumOfEvenIncrements =
78+
Maybe<Integer> sumOfEvenIncrements =
7979
reduceLeft((x, y) -> x + y,
8080
filter(x -> x % 2 == 0,
8181
map(x -> x + 1, asList(1, 2, 3, 4, 5))));
82-
//-> 12
82+
//-> Just 12
8383
```
8484

8585
Every function in lambda is [curried](https://www.wikiwand.com/en/Currying), so we could have also done this:
8686
```Java
87-
Fn1<Iterable<Integer>, Integer> sumOfEvenIncrementsFn =
87+
Fn1<Iterable<Integer>, Maybe<Integer>> sumOfEvenIncrementsFn =
8888
map((Integer x) -> x + 1)
89-
.andThen(filter(x -> x % 2 == 0))
90-
.andThen(reduceLeft((x, y) -> x + y));
89+
.fmap(filter(x -> x % 2 == 0))
90+
.fmap(reduceLeft((x, y) -> x + y));
9191

92-
Integer sumOfEvenIncrements = sumOfEvenIncrementsFn.apply(asList(1, 2, 3, 4, 5));
93-
//-> 12
92+
Maybe<Integer> sumOfEvenIncrements = sumOfEvenIncrementsFn.apply(asList(1, 2, 3, 4, 5));
93+
//-> Just 12
9494
```
9595

9696
How about the positive squares below 100:
@@ -106,7 +106,7 @@ We could have also used `unfoldr`:
106106
```Java
107107
Iterable<Integer> positiveSquaresBelow100 = unfoldr(x -> {
108108
int square = x * x;
109-
return square < 100 ? Optional.of(tuple(square, x + 1)) : Optional.empty();
109+
return square < 100 ? Maybe.just(tuple(square, x + 1)) : Maybe.nothing();
110110
}, 1);
111111
//-> [1, 4, 9, 16, 25, 36, 49, 64, 81]
112112
```
@@ -116,7 +116,7 @@ What if we want the cross product of a domain and codomain:
116116
```Java
117117
Iterable<Tuple2<Integer, String>> crossProduct =
118118
take(10, cartesianProduct(asList(1, 2, 3), asList("a", "b", "c")));
119-
//-> (1,"a"), (1,"b"), (1,"c"), (2,"a"), (2,"b"), (2,"c"), (3,"a"), (3,"b"), (3,"c")
119+
//-> [(1,"a"), (1,"b"), (1,"c"), (2,"a"), (2,"b"), (2,"c"), (3,"a"), (3,"b"), (3,"c")]
120120
```
121121

122122
Let's compose two functions:
@@ -125,9 +125,9 @@ Let's compose two functions:
125125
Fn1<Integer, Integer> add = x -> x + 1;
126126
Fn1<Integer, Integer> subtract = x -> x -1;
127127

128-
Fn1<Integer, Integer> noOp = add.andThen(subtract);
128+
Fn1<Integer, Integer> noOp = add.fmap(subtract);
129129
// same as
130-
Fn1<Integer, Integer> alsoNoOp = subtract.compose(add);
130+
Fn1<Integer, Integer> alsoNoOp = subtract.contraMap(add);
131131
```
132132

133133
And partially apply some:
@@ -144,7 +144,7 @@ And have fun with 3s:
144144

145145
```Java
146146
Iterable<Iterable<Integer>> multiplesOf3InGroupsOf3 =
147-
take(3, inGroupsOf(3, unfoldr(x -> Optional.of(tuple(x * 3, x + 1)), 1)));
147+
take(3, inGroupsOf(3, unfoldr(x -> Maybe.just(tuple(x * 3, x + 1)), 1)));
148148
//-> [[3, 6, 9], [12, 15, 18], [21, 24, 27]]
149149
```
150150

@@ -176,7 +176,7 @@ Check out the [semigroup](https://palatable.github.io/lambda/javadoc/com/jnape/p
176176

177177
```Java
178178
Monoid<Integer> multiply = monoid((x, y) -> x * y, 1);
179-
multiple.reduceLeft(emptyList()); //-> 1
179+
multiply.reduceLeft(emptyList()); //-> 1
180180
multiply.reduceLeft(asList(1, 2, 3)); //-> 6
181181
multiply.foldMap(Integer::parseInt, asList("1", "2", "3")); //-> also 6
182182
```

0 commit comments

Comments
 (0)