Skip to content

Instantly share code, notes, and snippets.

@ngbinh
Created March 14, 2016 15:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ngbinh/7089ad08ee71a5b7e42d to your computer and use it in GitHub Desktop.
Save ngbinh/7089ad08ee71a5b7e42d to your computer and use it in GitHub Desktop.
monix
val a = BehaviorChannel(1, OverflowStrategy.Unbounded)
val b = BehaviorChannel(1, OverflowStrategy.Unbounded)
val c = BehaviorChannel(1, OverflowStrategy.Unbounded)
val d = BehaviorChannel(1, OverflowStrategy.Unbounded)
val flatMapChannels = for {
aV <- a.dump("a")
bV <- b.dump("b")
} yield (aV -> bV)
flatMapChannels.dump("flatMap").foreach(s => println(s"flatMap $s"))
a.dump("a2").switchMap(a => b.dump("b2").map(b => a -> b)).dump("switchMap3").foreach(s => println(s"switchMap3 $s"))
c.dump("c").switchMap(c => d.dump("d").map(d => c -> d)).dump("switchMap").foreach(s => println(s"switchMap $s"))
d.dump("d2").switchMap(d => c.dump("c2").map(c => c -> d)).dump("switchMap2").foreach(s => println(s"switchMap2 $s"))
@ a := 2
1: a2-->2
0: b2-->1
1: switchMap3-->(2,1)
switchMap3 (2,1)
@ a := 3
// Nothing
@ a := 4
// Nothing
@ b := 2
1: b-->2
1: flatMap-->(1,2)
flatMap (1,2)
1: b2-->2
3: b2 canceled
1: b2-->2
2: switchMap3-->(2,2)
switchMap3 (2,2)
@ b := 3
2: b-->3
2: flatMap-->(1,3)
flatMap (1,3)
2: b2-->3
3: switchMap3-->(2,3)
switchMap3 (2,3)
@ b := 4
3: b-->4
3: flatMap-->(1,4)
flatMap (1,4)
3: b2-->4
4: switchMap3-->(2,4)
switchMap3 (2,4)
@ c := 2
1: c-->2
1: c2-->2
1: switchMap2-->(monifu.reactive.channels.BehaviorChannel@31bd0f57,2)
switchMap2 (monifu.reactive.channels.BehaviorChannel@31bd0f57,2)
0: d-->1
1: switchMap-->(2,1)
switchMap (2,1)
@ c := 3
2: c-->3
2: c2-->3
2: switchMap2-->(monifu.reactive.channels.BehaviorChannel@31bd0f57,3)
switchMap2 (monifu.reactive.channels.BehaviorChannel@31bd0f57,3)
0: d-->1
2: switchMap-->(3,1)
switchMap (3,1)
@ c := 4
3: c-->4
3: c2-->4
0: d-->1
3: switchMap-->(4,1)
3: switchMap2-->(monifu.reactive.channels.BehaviorChannel@31bd0f57,4)
switchMap (4,1)
switchMap2 (monifu.reactive.channels.BehaviorChannel@31bd0f57,4)
@ d := 2
4: d-->2
6: d canceled
4: d2-->2
1: d-->2
0: c2-->4
3: d canceled
7: switchMap2-->(4,2)
1: d-->2
switchMap2 (4,2)
3: d canceled
1: d-->2
7: switchMap-->(4,2)
switchMap (4,2)
@ d := 3
5: d2-->3
2: d-->3
8: switchMap-->(4,3)
switchMap (4,3)
0: c2-->4
8: switchMap2-->(4,3)
switchMap2 (4,3)
@ d := 4
6: d2-->4
3: d-->4
0: c2-->4
9: switchMap2-->(4,4)
switchMap2 (4,4)
9: switchMap-->(4,4)
switchMap (4,4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment