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
910
JavaSlang JavaDayKiev 2016
pivovarit
0
75
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
短期間での新規プロダクト開発における「コスパの良い」Goのテスト戦略」 / kamakura.go
n3xem
2
170
ドメインイベント増えすぎ問題
h0r15h0
2
290
Go の GC の不得意な部分を克服したい
taiyow
2
770
Recoilを剥がしている話
kirik
5
6.6k
From Translations to Multi Dimension Entities
alexanderschranz
2
130
Monixと常駐プログラムの勘どころ / Scalaわいわい勉強会 #4
stoneream
0
270
責務を分離するための例外設計 - PHPカンファレンス 2024
kajitack
1
570
テスト自動化失敗から再挑戦しチームにオーナーシップを委譲した話/STAC2024 macho
ma_cho29
1
1.3k
命名をリントする
chiroruxx
1
400
クリエイティブコーディングとRuby学習 / Creative Coding and Learning Ruby
chobishiba
0
3.9k
Effective Signals in Angular 19+: Rules and Helpers @ngbe2024
manfredsteyer
PRO
0
130
Асинхронность неизбежна: как мы проектировали сервис уведомлений
lamodatech
0
740
Featured
See All Featured
Fontdeck: Realign not Redesign
paulrobertlloyd
82
5.3k
Being A Developer After 40
akosma
87
590k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
232
17k
Optimising Largest Contentful Paint
csswizardry
33
3k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.1k
The Art of Programming - Codeland 2020
erikaheidi
53
13k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
191
16k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
44
9.3k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
38
1.9k
Side Projects
sachag
452
42k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
330
21k
GitHub's CSS Performance
jonrohan
1030
460k
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