Created
November 7, 2013 05:49
-
-
Save timjstewart/7349661 to your computer and use it in GitHub Desktop.
Fun with RxScala (FRP)
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
name := "app" | |
resolvers ++= Seq( | |
"Sonatype Snapshots" at "http://oss.sonatype.org/content/repositories/snapshots", | |
"Sonatype Releases" at "http://oss.sonatype.org/content/repositories/releases" | |
) | |
libraryDependencies ++= Seq( | |
"org.scalacheck" %% "scalacheck" % "1.10.1" % "test", | |
"log4j" % "log4j" % "1.2.17", | |
"com.netflix.rxjava" % "rxjava-scala" % "0.14.8" | |
) |
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
package com.timjstewart | |
import scala.concurrent._ | |
import rx.lang.scala._ | |
object Main extends App { | |
override def main(args: Array[String]): Unit = { | |
def observable(n: Int) = Observable[Int] { | |
obs: Observer[Int] => { | |
new Thread(new Runnable { | |
override def run(): Unit = { | |
for { | |
x <- (1 to 10) | |
} { | |
obs.onNext(x*n) | |
} | |
obs.onCompleted() | |
} | |
}).start() | |
new Subscription { | |
override def unsubscribe() = println("Unsubscribe") | |
} | |
} | |
} | |
observable(3) | |
.zip(observable(4)) | |
.finallyDo { () => println("Done") } | |
.subscribe { | |
x => println(s"I got a ${x._1} and a ${x._2}") | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment