Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Java Wars VIII: The Function Awakens
Search
Grzegorz Piwowarek
April 11, 2016
Programming
0
690
Java Wars VIII: The Function Awakens
Grzegorz Piwowarek
April 11, 2016
Tweet
Share
More Decks by Grzegorz Piwowarek
See All by Grzegorz Piwowarek
Javaslang DevoxxBE 2016
pivovarit
1
130
Javaslang DevoxxMA
pivovarit
2
1.1k
JavaSlang JavaDayKiev 2016
pivovarit
0
77
Javaslang - functional Java done right
pivovarit
0
220
Java 8 vs. Checked Exceptions
pivovarit
0
110
Java 8: Lambdas, Monads and Java Collections
pivovarit
1
110
Other Decks in Programming
See All in Programming
CSC305 Lecture 03
javiergs
PRO
0
240
iOSアプリの信頼性を向上させる取り組み/ios-app-improve-reliability
shino8rayu9
0
170
アメ車でサンノゼを走ってきたよ!
s_shimotori
0
210
Things You Thought You Didn’t Need To Care About That Have a Big Impact On Your Job
hollycummins
0
210
ソフトウェア設計の実践的な考え方
masuda220
PRO
4
540
私達はmodernize packageに夢を見るか feat. go/analysis, go/ast / Go Conference 2025
kaorumuta
2
520
Pythonスレッドとは結局何なのか? CPython実装から見るNoGIL時代の変化
curekoshimizu
5
1.7k
その面倒な作業、「Dart」にやらせませんか? Flutter開発者のための業務効率化
yordgenome03
0
110
Go言語の特性を活かした公式MCP SDKの設計
hond0413
1
210
Railsだからできる 例外業務に禍根を残さない 設定設計パターン
ei_ei_eiichi
0
420
Cloudflare AgentsとAI SDKでAIエージェントを作ってみた
briete
0
130
NetworkXとGNNで学ぶグラフデータ分析入門〜複雑な関係性を解き明かすPythonの力〜
mhrtech
3
1.2k
Featured
See All Featured
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
358
30k
A Tale of Four Properties
chriscoyier
160
23k
Measuring & Analyzing Core Web Vitals
bluesmoon
9
620
Bootstrapping a Software Product
garrettdimon
PRO
307
110k
The Language of Interfaces
destraynor
162
25k
Visualization
eitanlees
148
16k
jQuery: Nuts, Bolts and Bling
dougneiner
64
7.9k
Fashionably flexible responsive web design (full day workshop)
malarkey
407
66k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
15k
Build The Right Thing And Hit Your Dates
maggiecrowley
37
2.9k
Automating Front-end Workflow
addyosmani
1371
200k
What's in a price? How to price your products and services
michaelherold
246
12k
Transcript
Grzegorz Piwowarek
[email protected]
GitHub, Twitter :: @pivovarit
GitHub, Twitter :: @pivovarit VISIONS OF TONDAL.PL
None
None
None
None
Why?
//TODO: -lambda expressions -java.util.function -monad -java.util.Optional -java.util.stream.Stream GitHub, Twitter ::
@pivovarit
lambda expressions GitHub, Twitter :: @pivovarit
lambda expressions (...) -> statement - Anonymous function GitHub, Twitter
:: @pivovarit
lambda expressions x -> x + 1 GitHub, Twitter ::
@pivovarit
lambda expressions x -> x + 1 GitHub, Twitter ::
@pivovarit () -> 42
lambda expressions x -> x + 1 GitHub, Twitter ::
@pivovarit () -> 42 () -> {return 42;}
lambda expressions x -> x + 1 GitHub, Twitter ::
@pivovarit () -> 42 (x, y) -> {} () -> {return 42;}
lambda expressions x -> x + 1 - No type
information GitHub, Twitter :: @pivovarit
method references GitHub, Twitter :: @pivovarit
java.util.function GitHub, Twitter :: @pivovarit
Function<T, R>, BiFunction<T,U,R> Consumer<T> extends Function<T,Void> Supplier<T> extends Function<Void, T>
Predicate<T> extends Function<T, Boolean> UnaryOperator<T> extends Function<T, T> BinaryOperator<T> extends BiFunction<T,T,T> GitHub, Twitter :: @pivovarit
Function<T, R>, BiFunction<T,U,R> Consumer<T> extends Function<T,Void> Supplier<T> extends Function<Void, T>
Predicate<T> extends Function<T, Boolean> UnaryOperator<T> extends Function<T, T> BinaryOperator<T> extends BiFunction<T,T,T> GitHub, Twitter :: @pivovarit
Function<T, R>, BiFunction<T,U,R> Consumer<T> extends Function<T,Void> Supplier<T> extends Function<Void, T>
Predicate<T> extends Function<T, Boolean> UnaryOperator<T> extends Function<T, T> BinaryOperator<T> extends BiFunction<T,T,T> GitHub, Twitter :: @pivovarit
Function<T, R>, BiFunction<T,U,R> Consumer<T> extends Function<T,Void> Supplier<T> extends Function<Void, T>
Predicate<T> extends Function<T, Boolean> UnaryOperator<T> extends Function<T, T> BinaryOperator<T> extends BiFunction<T,T,T> GitHub, Twitter :: @pivovarit
Function<T, R>, BiFunction<T,U,R> Consumer<T> extends Function<T,Void> Supplier<T> extends Function<Void, T>
Predicate<T> extends Function<T, Boolean> UnaryOperator<T> extends Function<T, T> BinaryOperator<T> extends BiFunction<T,T,T> GitHub, Twitter :: @pivovarit
MONAD GitHub, Twitter :: @pivovarit
GitHub, Twitter :: @pivovarit
GOOGLE IMAGES...
GOOGLE IMAGES...
GOOGLE IMAGES...
GOOGLE IMAGES...
GOOGLE IMAGES...
GOOGLE IMAGES...
GOOGLE IMAGES...
GOOGLE IMAGES...
... GitHub, Twitter :: @pivovarit
MONAD Design pattern http://got-steam.com/ GitHub, Twitter :: @pivovarit
Why bother? : Boilerplate-- Readability++ Complexity-- GitHub, Twitter :: @pivovarit
Imperative approach GitHub, Twitter :: @pivovarit
Declarative approach GitHub, Twitter :: @pivovarit
Generic type: "unit" method: "bind" method: MONAD GitHub, Twitter ::
@pivovarit
Generic type: "unit" method: "bind" method: MONAD GitHub, Twitter ::
@pivovarit
Generic type: "unit" method: "bind" method: MONAD GitHub, Twitter ::
@pivovarit
Generic type: "unit" method: "bind" method: MONAD GitHub, Twitter ::
@pivovarit
GitHub, Twitter :: @pivovarit
GitHub, Twitter :: @pivovarit
GitHub, Twitter :: @pivovarit
http://www.ivanaborovnjak.com/project/box-in-a-box/ GitHub, Twitter :: @pivovarit
Solution GitHub, Twitter :: @pivovarit
Monads in Java 8 Optional Stream CompletableFuture GitHub, Twitter ::
@pivovarit
Monads in Java 8 Optional Stream CompletableFuture GitHub, Twitter ::
@pivovarit
Optional Encapsulation of operations on optional values GitHub, Twitter ::
@pivovarit
Optional Encapsulation of operations on optional values GitHub, Twitter ::
@pivovarit
Optional type: "unit": "bind": GitHub, Twitter :: @pivovarit
Optional type: Optional<T> "unit": "bind": GitHub, Twitter :: @pivovarit
Optional type: Optional<T> "unit": Optional.ofNullable(), Optional.of() "bind": GitHub, Twitter ::
@pivovarit
Optional type: Optional<T> "unit": Optional.ofNullable(), Optional.of() "bind": Optional.flatMap(), Optional.map() GitHub,
Twitter :: @pivovarit
Filtering an Optional .filter(Predicate<T>) GitHub, Twitter :: @pivovarit
Unwrapping an Optional .get() .orElse(T default) .orElseGet(Supplier<T>) .orElseThrow(Supplier<Ex>) .ifPresent(Consumer<T>) GitHub,
Twitter :: @pivovarit
GitHub, Twitter :: @pivovarit http://theworryfreelife.com/wp-content/uploads/2015/08/comfort-zone.jpg
Java 7 style GitHub, Twitter :: @pivovarit
Java 8 style GitHub, Twitter :: @pivovarit
Java 7,5 style ;) GitHub, Twitter :: @pivovarit
Java 7,5 style ;) GitHub, Twitter :: @pivovarit
GitHub, Twitter :: @pivovarit
GitHub, Twitter :: @pivovarit
Stream Encapsulation of operations on multiple items GitHub, Twitter ::
@pivovarit
Stream type: Stream<T> "unit": Stream.of(), Arrays.stream(), Collection.stream() "bind": Stream.flatMap() GitHub,
Twitter :: @pivovarit
Stream GitHub, Twitter :: @pivovarit
Stream GitHub, Twitter :: @pivovarit
Stream GitHub, Twitter :: @pivovarit
Imperative vs. Declarative GitHub, Twitter :: @pivovarit
Imperative vs. Declarative GitHub, Twitter :: @pivovarit
Stream && Optional GitHub, Twitter :: @pivovarit
Stream lazy-initialized nonreusable GitHub, Twitter :: @pivovarit
intermediate operations .map() .flatMap() .filter() .peek() GitHub, Twitter :: @pivovarit
intermediate operations .map() .flatMap() .filter() .peek() Stream not consumed: does
not print anything GitHub, Twitter :: @pivovarit
Consuming Stream .forEach(Consumer<T>) .collect() .reduce(BinaryOperator<T>) .allMatch(), anyMatch(), noneMatch() .findFirst(), findAny()
.count() .toArray() GitHub, Twitter :: @pivovarit
Stream.reduce() GitHub, Twitter :: @pivovarit
Collectors .toList(), toMap(), toSet(), toCollection() .minBy(), maxBy() .joining() .partitioningBy() ...and
many others GitHub, Twitter :: @pivovarit
Collectors.toList() GitHub, Twitter :: @pivovarit
Stream in APIs "any string".chars() Files.newDirectoryStream() Random.ints() ... GitHub, Twitter
:: @pivovarit
you want more? GitHub, Twitter :: @pivovarit
github.com/ TouK/ThrowingFunction http://www.javaslang.io/ GitHub, Twitter :: @pivovarit
Thank You! GitHub, Twitter :: @pivovarit
REFERENCES: -"MONADIC JAVA" BY MARIO FUSCO -"WHAT'S WRONG WITH JAVA
8" BY PIERRE-YVES SAUMONT -WWW.ORACLE.COM -"A FISTFUL OF MONADS" - LEARN YOU A HASKELL FOR GREAT GOOD