I completely forgot to write the summary of Scala Central number 11 I attended one month ago, but here I am for the number 12 just happened in the offices of Babylon Health. First talk was “Use and abuse of scala’s parser combinators” by Hugh Simpson (LinkedIn). He showed how to use combinators to parse a document.
I found particularly interesting how he handled the problem of generalising the order of the elements, and how he handled the possibility to put comments in every part of a document, parse them and ignore them. His code is available on Github and I will try to checkout it as soon as possible in order to understand what he was trying to explain us (unfortunately the topic is a bit complicated, even if I tried to use combinators by myself I have not really understood everything he said).
The second talk was “Scala Futures: may the fors be with you” by Lorenzo Barasti (LinkedIn – Twitter). The talk started by explaining what a Future is, an object holding a value which may become available at some point [in the future] (definition of scala-doc). It is good for running expensive computation off the main thread, retrieving data from a db without blocking, issuing an http request without waiting for the response or, of course, running concurrent computations. It gives all of this with responsiveness, error isolation, performance and code composability.
After this introduction he spent some slides in explaining how futures are mapped on threads, basically. So how the execution context uses a thread pool to associate tasks to threads and how the scheduler can allocate processing time to the different threads.
He then focused on four basic functions for handling futures: flatmap, foreach, recover and the andThen that can be used to wrap side effects and return the original value. “[andThen] returns a new future with exactly the same result as the current future, regardless of whether the current future failed or not. Once the current future is completed with the result, the closure corresponding to the andThen is invoked and then the new future is completed with the same result as this future” (from here). Finally he spoke about transform/transformWith (for fine grained control over exceptions) and for comprehension.
The last part of his talk was about Akka and the actor model, and some tricks and error to avoid using akka.
Last talk I have to admit I didn’t follow it very well, because it was after dinner and my concentration was not at its top. Harry Laoulakos (LinkedIn – website) spoke about monads and free monads (slides are here and code on Gitlab). At high level the talk was based on an Akka code that was doing only 3 or 4 things (parse a request, create a user, store the user in a db and return it) and how to rewrite it in a more compact way, knowing that we cannot use for expressions on Future[Option[?]]. He ended up speaking about monad transformers, free monads and Eff. A good starting point on free monads is this post. Eff are extensible effects, the project is on github, and a good starting point for the three topics Free Monads, monad transformers and Eff, is here.
This ended the talk. Stay tuned!