Skip to content

Commit 451da9b

Browse files
committed
doc update
1 parent 8f54c98 commit 451da9b

File tree

1 file changed

+55
-6
lines changed

1 file changed

+55
-6
lines changed

README.md

Lines changed: 55 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ in books or on the internet.
5959
}
6060
```
6161
1. it's often helpful to use currying(https://github.com/mtumilowicz/groovy-closure-currying)
62-
and functional interfaces to design API
62+
and functional interfaces to design API (package: **converter**)
6363
```
6464
@FunctionalInterface
6565
interface CurrableDoubleBinaryOperator extends DoubleBinaryOperator {
@@ -87,7 +87,7 @@ and functional interfaces to design API
8787
}
8888
}
8989
```
90-
1. use tuples and know the stream API
90+
1. use tuples and know the stream API (package: **customer**)
9191
```
9292
@Value
9393
@Builder
@@ -138,7 +138,8 @@ and functional interfaces to design API
138138
);
139139
}
140140
```
141-
1. try to avoid decorator pattern - use function composition instead
141+
1. try to avoid decorator pattern - use function
142+
composition instead (package: **decorator**)
142143
```
143144
@Value
144145
@RequiredArgsConstructor
@@ -196,7 +197,8 @@ and functional interfaces to design API
196197
}
197198
}
198199
```
199-
1. create complex DSL with hiding creation inside
200+
1. create complex DSL with hiding creation
201+
inside (package: **dsl**)
200202
```
201203
@Value
202204
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
@@ -234,7 +236,7 @@ and functional interfaces to design API
234236
**note that at any point we don't have direct access to the object,
235237
we cannot create object manually and we cannot reuse it
236238
(there is NO Mailer object)**
237-
1. know the comparator API
239+
1. know the comparator API (package: **person**)
238240
239241
suppose we want to compare person by name, then by surname (if surname is null goes first)
240242
```
@@ -268,6 +270,7 @@ and functional interfaces to design API
268270
list == [A, B_A, B_B, C_null, C_null2, C_A]
269271
```
270272
1. compose behaviours instead of accumulating objects in lists
273+
(package: **salary**)
271274
272275
suppose we want to calculate salary according to some
273276
salary rules
@@ -336,4 +339,50 @@ and functional interfaces to design API
336339
337340
expect:
338341
calculator.calculate(1000) == 1053
339-
```
342+
```
343+
1. strategy pattern (library of functions) (package: **strategy**)
344+
345+
we have `PriceProvider` to get current stock price (`Stock` class
346+
is as simple as possible)
347+
```
348+
@Value
349+
class PriceProvider {
350+
@Getter(AccessLevel.NONE)
351+
IntUnaryOperator priceSource;
352+
353+
int getPrice(int id) {
354+
return priceSource.applyAsInt(id);
355+
}
356+
}
357+
358+
@Value
359+
class Stock {
360+
int id;
361+
}
362+
```
363+
and suppose we want to calculate prices
364+
for a given stream of stocks (with some
365+
custom filtering)
366+
```
367+
@Value
368+
class Calculator {
369+
PriceProvider priceProvider;
370+
371+
int totalValues(List<Stock> integers, IntPredicate take) {
372+
return integers.stream()
373+
.map(Stock::getId)
374+
.mapToInt(priceProvider::getPrice)
375+
.filter(take)
376+
.sum();
377+
}
378+
379+
// library of functions
380+
static IntPredicate priceLessThan(int limit) {
381+
return it -> it < limit;
382+
}
383+
384+
static IntPredicate priceEquals(int limit) {
385+
return it -> it == limit;
386+
}
387+
}
388+
```

0 commit comments

Comments
 (0)