scala

Go-Scala-Go! What are the main differences?

I just found this web page comparing some code written in Scala, C# and Go. I am astonished to see how close Scala and Go code looks like, much more than Scala code compared to C# code. So my question is: What are the most significant differences between Scala and Go? ...

Scala - how to explicitly choose which overloaded method to use when one arg must be null?

All, I'm doing some image manipulation in Scala by making use of BufferedImages and Raster objects. I am attempting to get all the pixels in the buffered image with the following code. val raster = f.getRaster() // Preallocating the array causes ArrayIndexOutOfBoundsException .. http://forums.sun.com/thread.jspa?threadID=5297789 // R...

Abstract types versus type parameters

In what situations should abstract types be preferred over type parameters? ...

How would you compare a Scala-based web server with other web frameworks?

I have read about Scala but have not been able to do comparative analysis of other web programming frameworks on the basis of: maintainability (does the Scala language facilitate the maintainability of such a web framework, compared to, say, a Php-based one?), scalability (what OS is best adapted for a Scala wab server to be scalable?)...

Building a service for my website that has some foursquare features.

Hi everyone, I am interested in extending my website to provide a service which involves users "check in" in my university's campus. Since Location Based Services (LBS) is pretty new, and there are not much literature around that could provide relevant interests to this matter, I have the following questions to ask: First, I know that I...

Implementing an abstract method with a trait, inconsistent compiler behaviour?

I have a base class that comes from a Java library, whose code I cannot modify. This class (A) has an empty method (b) which should have been declared as abstract instead: class A { def b { } } I extend this class in Scala and override the method to make it abstract: abstract class AA extends A { override def b } Now I implemen...

Is there a systematic way to discover which implicit defs are in scope, and which one is bound at a particular point?

Often there's no need to pay any attention to implicit arguments in Scala, but sometimes it's very helpful to understand how the compiler is automatically providing them. Unfortunately, this understanding seems to be hard to obtain! Is there a general method to discover how an implicit parameter has been provided, in a given piece of...

Understanding infix method call and cons operator(::) in Scala

Hello, I'm quite new to Scala programming language, and was trying something out stucked in my mind while I was following the lecture notes at here. I think I couldn't really understand how cons operator works, here are some things I tried: I've created a pseudo-random number generator, then tried to create a list of one random value...

Partially applied recursive functions

def mainCaller() = { val name = "xyz" someList.foreach { u:Map => foo(name, u) } } def foo(name:String)(map:Map): Unit = { //match case.... //recursive call to foo in each case where name remains same, but map changes } how can I write foo as a partially applied function, where I dont have to pass name in every recursive call...

how to get OutputStream

I want to get an image from a response but I don't know how to get the OutputStream. I know in jsp, it is: response.getOutputStream() but what is it in liftweb ? Thanks a lot. ...

Interesting DSLs, Implemented in Scala?

I've seen BASIC and Apache Camel DSLs in Scala, and they're just fantastic. Any more examples of such DSLs? ...

Designing a convenient default valued map in Scala

I find myself using a lot of nested maps, e.g a Map[Int, Map[String, Set[String]]], and I'd like to have new Maps, Sets, etc. created automatically when I access a new key. E.g. something like the following: val m = ... m(1992)("foo") += "bar" Note that I don't want to use getOrElseUpdate here if I don't have to because it gets pretty...

A case class, inheriting from a class, is having issues being used as constructor parameter

I have this case class define: class Protocol(protocol:String) object Protocol { def apply(protocol:String) :Protocol = { protocol.toUpperCase match { case "HTTP" => Http() case "HTTPS" => Https() case "Ftp" => Ftp() case "Mail" =>Mail() case other => new Protocol(other) } } } cas...

Scala problem - how to run a program that is in a package?

I'm embarrassed to ask this, but I cannot figure out how to run a scala program that is defined to be within a package. Example: package foo.bar { object Hello { def main(args:Array[String]) { println("Hello") } } } After compiling the Hello.scala file, I get the expected directory structure -- ...

Is there a Scala-specific way to implement periodic execution?

AKA doing something at set intervals. For example, let's say I want to scan a certain directory every 60 seconds. In Java, I would use a ScheduledExecutorService like so: Executor pool = Executors.newScheduledThreadPool(10) pool.scheduleAtFixedRate(scanner, 0, 60, TimeUnit.SECONDS) and that works fine. The thing is, I'm thinking I'...

How can I connect to a postgreSQL database in scala?

I want to know how can I do following things in scala? Connect to a postgreSQL database. Write SQL queries like SELECT , UPDATE etc. to modify a table in that database. I know that in python I can do it using PygreSQL but how to do these things in scala? ...

Scala: How do I define an anonymous function with a variable argument list?

In Scala, how do I define an anonymous function which takes a variable number of arguments? scala> def foo = (blah:Int*) => 3 <console>:1: error: ')' expected but identifier found. def foo = (blah:Int*) => 3 ^ ...

How to implement a partial function in a subclass

Hi chaps, I'm trying to design a couple of classes that inherit a partial function, but I don't seem to be able to get the syntax quite right. My superclass looks like this: abstract class Controller { val react:PartialFunction[Event,Unit] } And the subclass looks like: class BoardRendererController(val renderer:BoardRenderer, ...

Scala: How do I use fold* with Map?

I have a Map[String, String] and want to concatenate the values to a single string. I can see how to do this using a List... scala> val l = List("te", "st", "ing", "123") l: List[java.lang.String] = List(te, st, ing, 123) scala> l.reduceLeft[String](_+_) res8: String = testing123 fold* or reduce* seem to be the right approach I just...

What's the name of this Scala infix syntax for specifying type params?

I noticed this interesting syntax the other day for specifying the type parameters for a Scala class. scala> class X[T, U] defined class X scala> new (Int X Int) res1: X[Int,Int] = X@856447 Is there a name for this sort of syntax? What's a good use case for it? ...