Skip to content

Instantly share code, notes, and snippets.

View thuutin's full-sized avatar

Tran Huu Tin thuutin

View GitHub Profile
@thuutin
thuutin / fibonacci.kt
Last active December 30, 2020 18:07
generate fibonacci sequence reactively
// Generate fibonacci sequence using Rxjava 2.
// This is an example to write a stream of events when future events depend on previous events, using reactive programming.
Flowable.generate(Callable { 0 to 1 }, BiFunction { prev:Pair<Int, Int>, emitter: Emitter<Int> ->
val next = prev.first + prev.second
emitter.onNext(prev.second)
prev.second to next
})
.take(100)
.subscribe {