Skip to content

Instantly share code, notes, and snippets.

@timjstewart
Created November 7, 2013 05:49
Show Gist options
  • Save timjstewart/7349661 to your computer and use it in GitHub Desktop.
Save timjstewart/7349661 to your computer and use it in GitHub Desktop.
Fun with RxScala (FRP)
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"
)
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