4 ms·
This article is pretty silly. Why use Akka for this at all? You don't need an untyped distributed system just to chain functions together. For logically chainin
by yummyfajitas 10y ago
This article is pretty silly. Why use Akka for this at all? You don't need an untyped distributed system just to chain functions together. For logically chaining functions together and accumulating errors, use Scalaz's \/:
http://eed3si9n.com/learning-scalaz/Either.html http://eed3si9n.com/learning-scalaz/Either.html
text >>= (t => if (containsForbiddenWord) { MyError.left[String] } else { t.right[MyError] })
>>= latexToUnicode _
>>= ...etc...
Unlike actors, this is deterministic and easily testable code.
If you really need to use a fancy concurrent system for this, Akka already has a built in piping/filtering framework called streams:
http://doc.akka.io/docs/akka/2.4.16/scala/stream/index.html http://doc.akka.io/docs/akka/2.4.16/scala/stream/index.html
Unlike this actor example, streams comes with built in backpressure/concurrency handling.
For new code you should probably be using streams rather than akka actors.
This article is neat for learning about actors, but you should almost certainly not write production code this way.
- hhandoko 10y agoPerhaps there was a constraint to use Java lang and not Scala, thus Scalaz probably can't apply here.
- yummyfajitas 10y agoTrue, I think of Akka as a Scala library but it works in Java too. But I'm sure Java has some similar deterministic abstraction. I know Java used to just use deterministic functions + exceptions, and that was hardly unreasonable.