Last active
August 29, 2015 13:57
-
-
Save timyates/9601597 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Grab( 'com.netflix.rxjava:rxjava-groovy:0.17.1' ) | |
import rx.Observable | |
import rx.Observer | |
import rx.subscriptions.Subscriptions | |
def fibObs = Observable.create { Observer<BigInteger> observer -> | |
Thread t | |
t = Thread.start { | |
def prev = 0G | |
def next = 0G | |
while( !t.interrupted() ) { | |
def ret = next | |
next = prev + ( next ?: 1 ) | |
prev = ret | |
observer.onNext( ret ) | |
} | |
} | |
Subscriptions.create { -> t.interrupt() } | |
} | |
fibObs.take( 10 ).subscribe { println it } | |
null |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment