background preloader

Scala

Facebook Twitter

Scalatra a tiny Sinatra-like web framework for Scala. Mongodb/casbah - GitHub. Scala School. Other Languages: About Scala school started as a series of lectures at Twitter to prepare experienced engineers to be productive Scala programmers. Scala is a relatively new language, but draws on many familiar concepts. Thus, these lectures assumed the audience knew the concepts and showed how to use them in Scala. We found this an effective way of getting new engineers up to speed quickly. Approach We think it makes the most sense to approach teaching Scala not as if it were an improved Java but instead as a new language. Most of the lessons require no software other than a Scala REPL. Also You can learn more elsewhere: Circumflex — the exquisite flavor of Scala development.

Scala 2.8 Collections API -- Arrays. Array is a special kind of collection in Scala. On the one hand, Scala arrays correspond one-to-one to Java arrays. That is, a Scala array Array[Int] is represented as a Java int[], an Array[Double] is represented as a Java double[] and a Array[String] is represented as a Java String[]. But at the same time, Scala arrays offer much more than their Java analogues. First, Scala arrays can be generic. That is, you can have an Array[T], where T is a type parameter or abstract type. Second, Scala arrays are compatible with Scala sequences - you can pass an Array[T] where a Seq[T] is required. Given that Scala arrays are represented just like Java arrays, how can these additional features be supported in Scala?

The Scala 2.8 design is much simpler. The interaction above demonstrates that arrays are compatible with sequences, because there's an implicit conversion from arrays to WrappedArrays. There is yet another implicit conversion that gets applied to arrays. Next: Strings. Scala Collections for the Easily Bored Part 2: One at a Time. 28 Jul 2008 As I hinted previously, this series is intended to delve into Scala’s extensive collections API and the many ways in which it can make your life easier.

Probably the most important operations you could ever perform on collections are those which examine each element, one at a time. After all, what’s a more common array idiom than looping over all values? In that vein, this article starts by looking at foreach, the imperative programmer’s bread-and-butter when it comes to types like Array and List. But rather than just stopping there, we also will look at more powerful, higher-order operations like fold, map and the ever-mysterious: flatMap. Iterating As I said above, looping over every item in a collection is probably the most heavily used operation in a programmer’s repertoire.

This code should be old hat to anyone coming from a Java background. The same approach is taken in Scala. Here we define an anonymous method (Scala’s name for a closure) which takes a single parameter. Setup - simple-build-tool - A build tool for Scala. Trying SBT (Simple Build Tool) for compiling a simple (one file, perhaps two) Scala application with some dependencies (Apache Pivot) on Windows as specifying all the jars on the command line quickly becomes annoying... (I try to convert the tutorial files to Scala). Following the instructions here I have put the jar file in C:\Java\scala-2.8.0.final\misc and the sbt.cmd file in C:\Java\scala-2.8.0.final\bin Content of the latter: @echo offjava -Xmx512M -jar C:\Java\scala-2.8.0.final\misc\sbt-launch-0.7.4.jar %* As shown above, I use the current version, 0.7.4, supposed to support Scala 2.8.

So far so good, when I type sbt on the command line, I get a prompt: Project does not exist, create new project? Trying what is suggested, I answer s for a simple "hello world" setup (Quick Setup), perfect for my simple need (precisely a HelloScala? So I find the LocalScala page. Do I have to read the whole wiki before starting to experiment? > sbtProject does not exist, create new project? The busy Java developer's guide to Scala: Functional programming for the object oriented. You never forget your first love. For me, her name was Tabinda (Bindi) Khan.

It was the halcyon years of my youth, seventh grade to be exact, and she was beautiful, smart, and, best of all, she laughed at my clumsy teenage boy jokes. We were "going out" (as it was called back then), on and off, for most of the seventh and eighth grades. But by ninth grade, we'd drifted apart, which is the polite way of saying that she got tired of hearing the same clumsy teenage boy jokes for two years running. I will never forget her (particularly because we ran into each other again at our 10-year high-school reunion); but more importantly, I will never lose those cherished — if somewhat exaggerated — memories.

Java programming, and object-orientation, was the first love for many programmers, and we treat it with the same respect and outright adoration I gave to Bindi. Time ultimately overcomes all first loves, however, and there comes a time to move on. I will always love you ... Enter Scala.