What's the point of having a powerful type system like Scala's and then throw it out of the window just so I can use a distributed framework?
https://github.com/scalaz/scalaz/tree/scalaz-seven/concurren...
https://github.com/scalaz/scalaz-stream
Like everything with Scalaz, the tools are great but almost completely undocumented.
Exactly. I will start considering scalaz once its authors grow up and realize that the lack of documentation is not a sign of quality.
They could just have kept the code proprietary.
The macro feature introduced in Scala 2.10 makes this possible.
http://doc.akka.io/docs/akka/2.2.0-RC1/scala/typed-channels....
[1] http://stackoverflow.com/questions/5547947/why-are-messages-...
findAirline: AirlineCode => Future[Option[Airline]]
getFlightsForToday: Airline => Future[Seq[Flight]]
findAvailable: Seq[Flight] => Constraints => Future[Option[Flight]
compose them so that I get: findFlight: AirlineCode => Constraints => Future[Flight]
I don't want `Future[Option[Flight]]` since Future has own error handling (using Try). No cheating by using scalaz monad transformer. def getOrThrow[T](x: Option[T]): T = x.getOrElse(throw new AirlineError)
def findFlight(code: AirlineCode, constraints: Constraints) = for {
airline <- findAirline(code).map(getOrThrow)
flights <- getFlightsForToday(airline)
available <- findAvailable(flights, constraints).map(getOrThrow)
} yield (available)
No idea why you consider using scalaz to be cheating. for
a <- forA
b <- forB
c <- forC(a)
it does not do a and b in parallel and then c, or does it? for {
a <- forA
b <- forB
} yield a + b
This runs them in parallel: val fa: Future[Int] = forA
val fb: Future[Int] = forB
for {
a <- fa
b <- fb
} yield a + b
(I dropped forC from your example as it has a dependency on the result for forA, and thus can't run in parallel.)I can't see the difference between your examples and so am confused why 1.) is serial 2.) is parallel.
You know that a for comprehension expands into calls to flatMap and map? So
for {
a <- forA
b <- forB
} yield a + b
expands to forA flatMap { a => forB map { b => a + b } }
Remember that forB creates and returns a future. Only when this future has been created will it start running.It should be apparent that forB is not evaluated till forA's future delivers a value, and thus the future returned by forB will run in serial with the future returned by forA.
In the other example the futures are created outside of the for comprehension, and thus start running in parallel.
Another feature that got my attention was the ability to have a SQL framework that handled things similar to LINQ. I haven't tried it much yet, but Squeryl[1] has looked promising for being a Scala equivalent. I may have to look into Akka more though as that will easily take care of async SQLite calls as well[2].
[1] http://squeryl.org/introduction.html
[2] http://www.gamlor.info/wordpress/2012/05/async-sql-and-akka/
I'm also looking forward to async SQL calls.
I've been building some Akka-based projects for a client and both they and I have been thrilled with the results. They're a startup that's gaining traction and they brought me in to help with scalability. I won't go so far as to say that Akka is a magic bullet but it makes reasoning about scalability far easier, though in our case we're mostly dancing around the IO bottleneck.
http://www.scala-lang.org/gsoc2013
http://www.google-melange.com/gsoc/projects/list/google/gsoc... (type "scala team" in "Organization" box
I've been working steadily in Scala since and currently do so professionally. I'm a fan, especially with the Akka actor framework.
Lately I've been playing with Play, Akka and ReactiveMongo. For-comprehensions offer a terrific abstraction for dealing with asynchronous code. My current side project is "Street View for Flights" implemented in the above stack. Lots of calls to third-party REST APIs after checking if data has already been retrieved and inserted into Mongo. Code like the following allows for controllers to be asynchronous while staying readable:
The advantage for me is that those futures could be redeemed either by finding the requested object in Mongo and on failure retrieving it from a third-party API while not blocking and keeping the code readable. Either way, the controller just gets a Future without blocking.Other parts of this project make heavy use of Akka actors to feed server-sent events (sort of a compromise between Comet and WebSockets). Development has been great fun because Scala really allows me to write code at a higher level. Asynchronous, typesafe, nullsafe code with the compiler as my safety net.