Last week we released Scaliak, a client library for Riak written in Scala. We received a lot of good feedback from its release. On the other hand, there were some who were critical about its use of Scalaz & the
IO monad. What struck me as interesting about that is if you are using the Riak Java Client then you’ve been using a more specific version of the
RiakOperation<T>, all along. The primary differences are that monadic capabilities aren’t exposed in the Riak Java Client, but are easy to add, and the
IO monad is more generic.
It’s not uncommon for blog posts about monads to say something like, “monads are cool because you have been using them all along and you didn’t even know it, and once you know it the world gets even more awesome.” I prefer to try to make this argument along the lines of, “monads are cool because you have had the potential to use them all along and when you recognize & leverage them in the structures you are using, your code gets better and then the world gets even more awesome.” Saying “your code gets better” is a broad statement, I know, but I will be expanding on that throughout this post.
Using the monad for
RiakOperation[T] we can chain together operations without having to call
execute() (performing the side-effect) until the chain has been completely constructed. This gives us greater control of the side-effects our application performs.