Skip to content

Instantly share code, notes, and snippets.

@olix0r
Forked from anonymous/jammer.scala
Last active December 18, 2015 14:59
Show Gist options
  • Save olix0r/5801066 to your computer and use it in GitHub Desktop.
Save olix0r/5801066 to your computer and use it in GitHub Desktop.
import com.twitter.finagle.{Filter, Service}
import com.twitter.util.{Await, Future}
case class Fruit(flavor: String)
case class Veggie(flavor: String)
case class Jam(flavor: String)
object Jammer extends Service[Veggie, Jam] {
def apply(veg: Veggie) =
Future value Jam(veg.flavor)
}
object FruitToVeg extends Filter[Fruit, Jam, Veggie, Jam] {
def apply(fruit: Fruit, jammer: Service[Veggie, Jam]) =
jammer(Veggie(fruit.flavor))
}
val fruits = "apple" :: "banana" :: "cherry" :: "durian" :: Nil
val jammer = FruitToVeg andThen Jammer
try {
val jams = Await result {
Future collect {
fruits map { Fruit(_) } map {
jammer(_) map { _.flavor }
}
}
}
println("Made some tasty jam: %s".format(jams.mkString(", ")))
} catch { case e =>
println("Error: %s".format(e.getMessage))
}
@olix0r
Copy link
Author

olix0r commented Jun 17, 2013

:; bin/scala -i util/util-app -i finagle/finagle-core jammer.scala
Made some tasty jam: apple, banana, cherry, durian

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment