-
Publish JAR artifact using Gradle to Artifactory
So I have wasted (invested) a day or two just to find out how to publish a JAR using Gradle to a locally running Artifactory server. I used Gradle Artifactory plugin to do the publishing. I was lost in endless loop of including various versions of various plugins and executing all sorts of tasks. Yes,…
-
Scala for-comprehension with concurrently running futures
Can you tell what’s the difference between the following two? If yes, then you’re great and you don’t need to read further. Version 1: val milkFuture = future { getMilk() } val flourFuture = future { getFlour() } for { milk <- milkFuture flour <- flourFuture } yield (milk + flour) Version 2: for {…
-
The best code coverage for Scala
The best code coverage metric for Scala is statement coverage. Simple as that. It suits the typical programming style in Scala best. Scala is a chameleon and it can look like anything you wish, but very often more statements are written on a single line and conditional “if” statements are used rarely. In other words,…
-
Await without waiting
Scala has recently introduced async and await features. It allows to write clean and easy-to-understand code for cases where otherwise complex composition of futures would be needed. The same thing already exists in C# for quite a while. But I always had a feeling that I don’t really know how does it work. I tried…
-
Scala Wonderland: Case classes and pattern matching
Pattern matching is usually related to text search. In Scala it has much more sophisticated usage. You can write exciting decision logic when used together with case classes. Even after understanding what the two things mean I wasn’t able to use them as they deserve. It takes a while to really grasp them. Long and…
-
Scala Wonderland: Semicolons, singletons and companion objects
In Scala you may usually omit semicolon at the end of a statement. It is required if more statements are on a single line. Unfortunately there are cases when compiler doesn’t undrstand the code as you would expect. For example following is treated as two statements a and +b: a + b Solution is to…
-
Scala Wonderland: Lists
In functional style methods should not have side effects. A consequence of this philosophy is that List is immutable in Scala. Construction of a List is simple. val abc = List(“a”, “b”, “c”) There is one trick in the previous code. A common trick in Scala. It invokes method named apply on List companion object.…
-
Scala Wonderland: The functional style
Scala encourages to use a functional style of programming. For programmers coming from imperative world of Java or C# it is the main challenge. The first step is to recognize the difference between functional and imperative programming. Scala has two keywords for variable declaration: var – mutable variables val – immutable variables One sign of…
-
Scala Wonderland #1: All operations are method calls
I’ve started learning Scala two months ago and I can’t get back to Murakami’s 1Q84 so exciting it is. In the coming series I’d like to share my excitement with you. It won’t be yet another step-by-step tutorial. I’ll share features that made me think (IBM should be proud of me). For whatever reason. val…