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
680
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
930
JavaSlang JavaDayKiev 2016
pivovarit
0
76
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
テストコード書いてみませんか?
onopon
2
340
ATDDで素早く安定した デリバリを実現しよう!
tonnsama
1
1.9k
EC2からECSへ 念願のコンテナ移行と巨大レガシーPHPアプリケーションの再構築
sumiyae
3
590
ある日突然あなたが管理しているサーバーにDDoSが来たらどうなるでしょう?知ってるようで何も知らなかったDDoS攻撃と対策 #phpcon.2024
akase244
2
7.7k
DMMオンラインサロンアプリのSwift化
hayatan
0
190
生成AIでGitHubソースコード取得して仕様書を作成
shukob
0
630
どうして手を動かすよりもチーム内のコードレビューを優先するべきなのか
okashoi
3
870
Simple組み合わせ村から大都会Railsにやってきた俺は / Coming to Rails from the Simple
moznion
3
2.2k
令和7年版 あなたが使ってよいフロントエンド機能とは
mugi_uno
10
5.2k
アクターシステムに頼らずEvent Sourcingする方法について
j5ik2o
6
700
非ブラウザランタイムとWeb標準 / Non-Browser Runtimes and Web Standards
petamoriken
0
430
知られざるDMMデータエンジニアの生態 〜かつてツチノコと呼ばれし者〜
takaha4k
1
450
Featured
See All Featured
Gamification - CAS2011
davidbonilla
80
5.1k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
365
25k
Learning to Love Humans: Emotional Interface Design
aarron
274
40k
Fantastic passwords and where to find them - at NoRuKo
philnash
50
2.9k
Music & Morning Musume
bryan
46
6.3k
Code Review Best Practice
trishagee
65
17k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
226
22k
RailsConf 2023
tenderlove
29
970
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
33
2.7k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
29
960
Done Done
chrislema
182
16k
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