The Ease Of Using�Higher Order Operators
Created by Michael Hladky
@Michael_Hladky
ng-India
Agenda
@Michael_Hladky
ng-India
combine�Latest
expand
combineAll
withLatest�From
forkJoin
zip
zipAll
merge�(deprecated)
concat�(deprecated)
mergeMap�(alias flatMap)
mergeAll
mergeScan
merge
concat
concatMap
concatAll
concatMapTo
switchMap
switchMapTo
exhaustMap
switchAll
scan
exhaust
startsWith
endsWith
groupBy
onError�ResumeNext
audit
buffer
bufferToggle
skipUntil
debounce
takeUntil
windowCount
window
windowTime
windowWhen
windowToggle
catchError
38�Operators
mapTo
map
Angular by heart and code
Development, Workshops, Community
Michael@Hladky.at
VIENNA
DELHI
Terminology
@Michael_Hladky
ng-India
Observable Order
First-Order Observable
2
Second-Order Observable
1
Third-Order Observable
@Michael_Hladky
ng-India
Higher Order Observable
First-Order Observable
Higher-Order Observable
2
1
@Michael_Hladky
ng-India
Operator Order
firstOrder( => )
secondOrder( => )
secondOrder( => )
secondOrder( => )
thirdOrder( => )
@Michael_Hladky
ng-India
Higher Order Operator
firstOrder( => )
higherOrder( => )
@Michael_Hladky
ng-India
Static Function
output$
static function
@Michael_Hladky
ng-India
Operator Function
output$
operator function
input$
@Michael_Hladky
ng-India
Categorisation
@Michael_Hladky
ng-India
Higher Order
First Order
1
2
3
4
STATIC FUNCTION
OPERATOR FUNCTION
output$
static function
output$
operator function
input$
Algebraic Approach
@Michael_Hladky
ng-India
Algebra:� from Arabic "al-jabr", �literally meaning �"reunion of broken parts"
Wikipedia
“
”
@Michael_Hladky
Algebra: Reunion Of Broken Parts
switch
concat
All
exhaust
merge
Map
To
Map
switchMapTo
switch
To
@Michael_Hladky
Overview Of�Explained Operators
@Michael_Hladky
ng-India
combine�Latest
expand
combineAll
withLatest�From
forkJoin
zip
zipAll
merge�(deprecated)
concat�(deprecated)
mergeMap�(alias flatMap)
mergeAll
mergeScan
merge
concat
concatMap
concatAll
concatMapTo
switchMap
switchMapTo
exhaustMap
switchAll
exhaust
startsWith
endsWith
groupBy
onError�ResumeNext
audit
buffer
bufferToggle
skipUntil
debounce
takeUntil
windowCount
window
windowTime
windowWhen
windowToggle
catchError
Operators�Explained
Primitive Operator Parts
@Michael_Hladky
ng-India
Operator Parts For Transformations
to
map
@Michael_Hladky
ng-India
merge�(deprecated)
concat�(deprecated)
mergeAll
mergeScan
merge
concat
concatAll
exhaust
expand
combine�Latest
switchAll
zip
withLatest�From
zipAll
combineAll
startsWith
endsWith
forkJoin
combine�Latest
map
mergeMap�(alias flatMap)
concatMap
concatMapTo
switchMap
switchMapTo
mapTo
exhaustMap
map
mergeMap�(alias flatMap)
concatMap
concatMapTo
switchMap
switchMapTo
mapTo
exhaustMap
map
1
2
input$:
output$:
2
4
3
6
4
8
map(v => v * 2)
@Michael_Hladky
ng-India
map
1
?
input$:
output$:
2
?
3
?
4
?
map(v => )
?
@Michael_Hladky
ng-India
map
1
input$:
output$:
2
3
4
map(v => of(v) )
@Michael_Hladky
ng-India
When to use map?
@Michael_Hladky
ng-India
concatMapTo
switchMapTo
mapTo
map
merge�(deprecated)
concat�(deprecated)
mergeMap�(alias flatMap)
mergeAll
mergeScan
merge
concat
concatMap
concatAll
concatMapTo
switchMap
switchMapTo
mapTo
exhaust
exhaustMap
expand
combine�Latest
switchAll
zip
scan
withLatest�From
zipAll
race
combineAll
race
(deprecated)
startsWith
endsWith
reduce
forkJoin
combine�Latest
mapTo
1
42
input$:
output$:
2
42
3
42
4
42
mapTo(42)
@Michael_Hladky
ng-India
When to use to?
@Michael_Hladky
ng-India
Flattening And Merging�Operators
@Michael_Hladky
ng-India
Sorting Of Values Related To Time
switch
concat
exhaust
merge
@Michael_Hladky
ng-India
Sorting Of Values Related To Time
1
2
b
a
merge
concat
switch
exhaust
input1$
input2$
1
2
b
a
1
2
1
b
a
1
b
b
a
2
8 Parts�20 Operators
@Michael_Hladky
ng-India
merge
@Michael_Hladky
ng-India
STATIC
OPERATOR
map
merge�(deprecated)
concat�(deprecated)
mergeMap�(alias flatMap)
mergeAll
mergeScan
merge
concat
concatMap
concatAll
concatMapTo
switchMap
switchMapTo
to
exhaustMap
expand
all
switchAll
exhaust
startsWith
endsWith
merge�(deprecated)
mergeMap�(alias flatMap)
mergeAll
merge
mergeScan
merge | static function
i1$
output$
i2$
merge([i2$, i2$])
@Michael_Hladky
ng-India
mergeMap | operator function
a
A
input$:
output$:
A
ws$:
b
A
A
B
B
B
B
ws1$:
ws2$:
mergeMap()
@Michael_Hladky
ng-India
When to use merge?
Guess what happens�if param concurrent is set to 1
!
@Michael_Hladky
ng-India
concat
@Michael_Hladky
ng-India
STATIC
OPERATOR
map
concat�(deprecated)
concat
concatMap
concatAll
concatMapTo
switchMap
switchMapTo
mapTo
exhaustMap
expand
switchAll
exhaust
startsWith
endsWith
merge�(deprecated)
mergeAll
merge
mergeScan
mergeMap�(alias flatMap)
concat�(deprecated)
concat
concatMap
concatAll
concatMapTo
startsWith
endsWith
concat | static function
w1$:
A
A
A
w1$:
output$:
A
A
A
B
B
B
B
w2$:
w2$:
B
B
concat([w1$,w2$])
@Michael_Hladky
ng-India
startWith | operator function
w$:
B
B
B
output$:
B
B
B
A
A
A
A
input$:
input$:
A
A
concat(w$):
startWith(w$)
@Michael_Hladky
ng-India
endWith | operator function
w$:
B
B
B
output$:
B
B
B
A
A
input$:
input$:
A
A
concat(w$):
A
A
endWith(w$):
@Michael_Hladky
ng-India
concatMap | operator function
a
A
input$:
output$:
A
w$:
b
A
A
B
B
B
B
w1$:
w2$:
concatMap(fn)
@Michael_Hladky
ng-India
concatMapTo | operator function
a
1
input$:
output$:
2
w$:
b
1
2
1
2
1
2
1
2
w$:
w$:
concatMapTo(w$)
@Michael_Hladky
ng-India
When to use concat?
Concat is merge with �concurrency set to 1
!
@Michael_Hladky
ng-India
switch
@Michael_Hladky
ng-India
STATIC
OPERATOR
map
switchMap
switchMapTo
mapTo
exhaustMap
expand
switchAll
exhaust
merge�(deprecated)
mergeAll
merge
mergeScan
mergeMap�(alias flatMap)
concat�(deprecated)
concat
concatMap
concatAll
concatMapTo
startsWith
endsWith
switchMap
switchMapTo
switchAll
switchMap| operator function
a
A
input$:
output$:
A
w$:
b
A
A
B
B
B
B
w1$:
w2$:
switchMap(fn)
@Michael_Hladky
ng-India
switchMapTo| operator function
a
1
input$:
output$:
2
w$:
b
1
2
1
2
1
2
1
2
w$:
w$:
switchMapTo(w$)
@Michael_Hladky
ng-India
When to use switch?
�
@Michael_Hladky
ng-India
exhaust
@Michael_Hladky
ng-India
STATIC
OPERATOR
map
mapTo
exhaustMap
expand
exhaust
merge�(deprecated)
mergeAll
merge
mergeScan
mergeMap�(alias flatMap)
concat�(deprecated)
concat
concatMap
concatAll
concatMapTo
startsWith
endsWith
exhaustMap
exhaust
switchMap
switchMapTo
switchAll
exhaustMap| operator function
a
A
input$:
output$:
A
w$:
b
A
A
C
w1$:
w3$:
c
C
C
C
exhaustMap()
@Michael_Hladky
ng-India
When to use exhaust?
@Michael_Hladky
ng-India
Combining Operators
@Michael_Hladky
ng-India
Grouping Of Values Triggered By Events
zip
combine
forkJoin
withLatest
@Michael_Hladky
ng-India
Grouping Of Values Triggered By Events
1
2
b
a
3
[1,a]
[2,a]
[2,b]
[3,b]
[3,b]
[1,a]
[2,b]
[2,a]
[3,b]
combine
forkJoin
zip
withLatest
input1$
input2$
6 Parts�10 Operators
@Michael_Hladky
ng-India
STATIC
OPERATOR
combineLatest�(deprecated)
withLatestFrom
forkJoin
race
(deprecated)
combineAll
combineLatest
race
zip�(deprecated)
zip
zipAll
zip
zipAll
zip�(deprecated)
zip
a
input1$:
input2$:
b
2
c
3
d
4
output$:
a1
b2
c3
d4
1
@Michael_Hladky
ng-India
When to use zip?
@Michael_Hladky
ng-India
STATIC
OPERATOR
combineLatest�(deprecated)
withLatestFrom
forkJoin
race
(deprecated)
zip�(deprecated)
zip
zipAll
combineAll
combineLatest
race
combineLatest�(deprecated)
combineAll
combineLatest
forkJoin
combineLatest | static function
a
input1$:
input2$:
b
2
c
3
d
4
output$:
a1
b2
a2
c2
c3
d3
d4
1
@Michael_Hladky
ng-India
When to use combineLatest?
@Michael_Hladky
ng-India
forkJoin
a
input1$:
input2$:
b
2
c
3
d
4
output$:
a1
b2
a2
c2
c3
d3
d4
1
@Michael_Hladky
ng-India
When to use forkJoin?
@Michael_Hladky
ng-India
STATIC
OPERATOR
combineLatest�(deprecated)
withLatestFrom
forkJoin
race
(deprecated)
zip�(deprecated)
zip
combineLatest
race
zipAll
combineAll
withLatestFrom
withLatestFrom
a
input$:
withLatestFrom(i2$):
b
2
c
3
d
4
output$:
a1
b2
c2
d3
1
i2$:
2
3
4
1
@Michael_Hladky
ng-India
When to use withLatestFrom?
@Michael_Hladky
ng-India
“All” Operators
@Michael_Hladky
ng-India
Operations On HOB’s
(Higher Order Observables)
all
@Michael_Hladky
ng-India
All
hoo$:
@Michael_Hladky
ng-India
STATIC
OPERATOR
exhaust
zipAll
combineAll
mergeAll
concatAll
switchAll
exhaust
zipAll
combineAll
mergeAll
concatAll
switchAll
map
1
input$:
output$:
2
3
4
map(v => of(v) )
@Michael_Hladky
ng-India
mergeAll | operator function
input$:
o1$
o2$
@Michael_Hladky
ng-India
mergeAll | operator function
o1$:
output$:
o2$:
input$:
o1$
o2$
mergeAll()
@Michael_Hladky
ng-India
concatAll | operator function
input$:
o1$
o2$
@Michael_Hladky
ng-India
concatAll | operator function
o1$:
output$:
o2$:
input$:
o1$
o2$
concatAll()
@Michael_Hladky
ng-India
switchAll | operator function
input$:
o1$
o2$
@Michael_Hladky
ng-India
switchAll | operator function
o1$:
output$:
o2$:
input$:
o1$
o2$
switchAll()
@Michael_Hladky
ng-India
exhaust | operator function
o1$
input$:
o2$
o3$
A
A
B
B
C
C
@Michael_Hladky
ng-India
exhaust | operator function
o1$
A
input$:
output$:
A
o2$
A
A
C
w1$:
w3$:
o3$
C
C
C
exhaust()
@Michael_Hladky
ng-India
zipAll | operator function
o1$
o2$
input1$:
@Michael_Hladky
ng-India
zipAll | operator function
a
i1$:
i2$:
b
2
c
3
d
4
output$:
b2
c3
d4
1
o1$
o2$
input1$:
a1
@Michael_Hladky
ng-India
combineAll | operator function
input1$:
o1$
o2$
@Michael_Hladky
ng-India
combineAll | operator function
a
i1$:
i2$:
b
2
c
3
d
4
output$:
b2
c2
c3
d3
d4
1
o1$
o2$
input1$:
a1
a2
@Michael_Hladky
ng-India
Done With Operators
@Michael_Hladky
ng-India
combine�Latest
expand
combineAll
withLatest�From
forkJoin
mapTo
zip
zipAll
map
merge�(deprecated)
concat�(deprecated)
mergeMap�(alias flatMap)
mergeAll
mergeScan
merge
concat
concatMap
concatAll
concatMapTo
switchMap
switchMapTo
exhaustMap
switchAll
exhaust
startsWith
endsWith
groupBy
onError�ResumeNext
audit
buffer
bufferToggle
skipUntil
debounce
takeUntil
windowCount
window
windowTime
windowWhen
windowToggle
catchError
24.5/38�Operators�64%
When to use all?
@Michael_Hladky
ng-India
bit.ly/rx-marble-design-system�bit.ly/marble-design-system
1
Time
2
Time Span
42ms
3
Consumer Event
4
Notification
5
Completion
6
Error
7
Operator
opr
8
Operator Contex
opr
9
Operation
@Michael_Hladky
ng-India
Thanks for your time!
Michael Hladky
michael@hladky.at�github.com/BioPhoton�angular-college.com
My name is Michael , If you have� any questions just ping me.
@Michael_Hladky
ng-India