Scala Programming for Android

I’ve written some basic Android applications in Scala, nothing too epic. Not being a Java programmer I was suggested to use a “treeshake”, I was explained by a friend that this strips out all the unnecessary libraries from the jar files. I have not documented it, but I found that someone else already has: http://chneukirchen.org/blog/archive/2009/04/programming-for-android-with-scala.html … Read more

What does a lazy val do?

The difference between them is, that a val is executed when it is defined whereas a lazy val is executed when it is accessed the first time. scala> val x = { println(“x”); 15 } x x: Int = 15 scala> lazy val y = { println(“y”); 13 } y: Int = <lazy> scala> x … Read more

How to use Shapeless in a Quasiquote?

This is my working solution using old-style macro annotations. import scala.language.experimental.macros import scala.reflect.macros.blackbox.Context import scala.annotation.StaticAnnotation class fieldable extends StaticAnnotation { def macroTransform(annottees: Any*): Any = macro fieldableMacro.impl } object fieldableMacro { def impl(c: Context)(annottees: c.Expr[Any]*): c.Tree = { import c.universe._ annottees.map(_.tree) match { case (param @ q”case class $className(..$fields)”) :: Nil => { val implicits … Read more

Difference between method and function in Scala

Jim has got this pretty much covered in his blog post, but I’m posting a briefing here for reference. First, let’s see what the Scala Specification tell us. Chapter 3 (types) tell us about Function Types (3.2.9) and Method Types (3.3.1). Chapter 4 (basic declarations) speaks of Value Declaration and Definitions (4.1), Variable Declaration and … Read more

Scala: join an iterable of strings

How about mkString ? theStrings.mkString(“,”) A variant exists in which you can specify a prefix and suffix too. See here for an implementation using foldLeft, which is much more verbose, but perhaps worth looking at for education’s sake.