A Reactive State of Mind
@colinmlee
Complexity = BAD
Functions = SIMPLE
Colin Lee
@colinmlee
Building Android team
@VidkuHQ,
makers of Flipgrid
30 years programming
Hate
Fear
Ignorance
We shouldn't need holy war to spread revolutionary ideas.
Want functional language depth?
See Brian Maddy's talk.
Looking for depth on RxJava?
See Dan Lew's talk.
The old way is complex.
Complexity = BAD
Functions = SIMPLE
I had a problem so I thought to use Java Design Patterns
Some Deep Hippie Insight:
Is
"Netflix is a big believer in the Rx model... it spreads deeper into our code the more we use it."
"If asynchronous spaghetti code were a disease, Rx is the cure.”
"[Our] desktop developers loved Rx so much that the Mac team created their own version."
Is
List<Integer> numbers =
Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8);
numbers.stream()
.filter(num -> num > 4)
.map(num -> num * 10)
.forEach(System.out::println);
// outputs 50, 60, 70, 80List<Integer> numbers =
Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8);
Observable.from(numbers)
.filter(num -> num > 4)
.map(num -> num * 10)
.subscribe(System.out::println);
// outputs 50, 60, 70, 80Observable<Result> dbResult =
numbersObservable
.flatMap(num -> database(num))
.filter(obj -> obj.newer(cacheExp);
Observable<Result> netResult =
numbersObservable
.flatMap(num -> network(
"http://example.com/" + num));
Observable.merge(dbResult, netResult)
.subscribeOn(Schedulers.io())
.observeOn(Schedulers.trampoline())
.subscribe(System.out::println);
// outputs result of http://example.com/
// with paths of /50, /60, /70, /80Goes Beyond Rx
Rx is best of both worlds.
Some Deep Hippie Insight:
main =
asText <<
List.map (\x->x*10) <|
List.filter (\x->x>4) [1..8]
-- prints 50, 60, 70, 80Complexity = BAD
Functions = SIMPLE