Merge sort is a classical “divide and conquer” sorting algorithm. You should have to never write one because you’d be silly to do that when a standard library class already will already do it for you. But, it is useful to demonstrate a few characteristics of programming techniques in Scala. Firstly a quick recap on the merge sort. It is ...
Read More »Home » JVM Languages » Scala »
Lazy sequences in Scala and Clojure
Lazy sequences (also known as streams) are an interesting functional data structure which you might have never heard of. Basically lazy sequence is a list that is not fully known/computed until you actually use it. Imagine a list that is very expensive to create and you don’t want to compute too much – but still allow clients to consume as ...
Read More »Advanced routing in Play Framework
We frequently get questions about how to meet all sorts of different routing needs in Play Framework. While the built in router is enough for most users, sometimes you may encounter use cases where it’s not enough. Or, maybe you want a more convenient way to implement some routing pattern. Whatever it is, Play will allow you to do pretty ...
Read More »Scala traits implementation and interoperability. Part II: Traits linearization
This is a continuation of Scala traits implementation and interoperability. Part I: Basics. Dreadful diamond problem can be mitigated using Scala traits and a process called linearization. Take the following example: trait Base { def msg = "Base" } trait Foo extends Base { abstract override def msg = "Foo -> " ...
Read More »WatchService combined with Akka actors
WatchService is a handy class that can notify you about any file system changes (create/update/delete of file) in a given set of directories. It is described nicely in the official documentation so I won’t write another introduction tutorial. Instead we will try to combine it with Akka to provide fully asynchronous, non-blocking file system changes notification mechanism. And we will ...
Read More »Becoming Acquainted with Scala
There are many touted benefits of the Scala programming language, especially for Java developers. Among others, Scala’s advertised strengths and advantages include the following: Runs on the Java Virtual Machine (JVM) Able to run on numerous hardware and operating systems platforms Access to rich set of libraries and functionality in the JDK Access to the broad Java ecosystem and its ...
Read More »Synchronizing transactions with asynchronous events in Spring
Today as an example we will take a very simple scenario: placing an order stores it and sends an e-mail about that order: @Service class OrderService @Autowired() (orderDao: OrderDao, mailNotifier: OrderMailNotifier) { @Transactional def placeOrder(order: Order) { orderDao save order mailNotifier sendMail order } } So far so good, but e-mail ...
Read More »Scala traits implementation and interoperability. Part I: Basics
Traits in Scala are similar to interfaces, but much more powerful. They allow implementations of some of the methods, fields, stacking, etc. But have you ever wondered how are they implemented on top of JVM? How is it possible to extend multiple traits and where the implementations go to? In this article, based on my StackOverflow answer, I will give ...
Read More »FitNesse your ScalaTest with custom Scala DSL
This article won’t be about FitNesse. As matter of fact I don’t like this tool very much and it seems to be loosing momentum, judging by the traffic on an official mailing list. Instead we will implement trivial internal DSL on top of Scala to simplify testing code, inspired by DoFixture. DoFixture in FitNesse allows one to write very readable ...
Read More »