scala

What is a proper way to manage flexible, typed, immutable data structures in Scala?

Right now I have classes like: abstract class Record { // Required fields val productCode:Option[String] val price:Option[Double] // Optional fields val notes:Option[String] = None val used:Option[Boolean] = Option(false) } Then create them: val r = new Record { override val productCode = Option("abc") override val p...

Why does Scala create a ~/tmp directory when I run a script?

When I execute a Scala script from the command line, a directory named "tmp" is created in my home directory. It is always empty, so I simply deleted it without any apparent problem. Of course, when I run another Scala script, it reappears. Is there a configuration file/flag by which I can change this behavior? Thanks. ...

Easiest way of getting third party database information into java objects

I am making some small "business intelligence" applications/tools that need to talk to other systems. Primarily accounting systems that believe that databases are an integration layer (or are too lazy to provide an api). What's the easiest way of getting specific data out of a third party database and into my Java objects? Notes: (I...

scala 2.8 breakout

In Scala 2.8, there is an object in scala.collection.package.scala: def breakOut[From, T, To](implicit b : CanBuildFrom[Nothing, T, To]) = new CanBuildFrom[From, T, To] { def apply(from: From) = b.apply() ; def apply() = b.apply() } I have been told that this results in: > import scala.collection.breakOut > val map : Map[Int,...

Is there a comparison between Scala and Google 'Go' language (feature by feature)?

I wonder if someone can produce a comparison between Scala and Google 'Go' language (feature by feature, like concurrency models, collections, etc.)? ...

How can I create a typed Tuple2 from Java / Spring?

I want to be able to create a Tuple2 from spring config where I explicitly declare the types of my parameters: <bean class="scala.Tuple2"> <constructor-arg index="0" value="Europe/London" type="java.util.TimeZone" /> <constructor-arg index="1" value="America/New_York" type="java.util.TimeZone" /> </bean> This does not work...

+=/*=/etc operators on AnyVal types (Int,Double,etc...) in Scala

Where exactly are the *=/+=/etc methods declared for the subclasses of AnyVal? I assume something special is done for these types because as a val those are invalid but as a var they are fine. Is this just yet more syntatic sugar ? I assume it is turning a *= 5 into a = a * 5 which obviously fails for a val. Is this intuition corr...

scala 2.8 CanBuildFrom

Following on from another question I asked, I wanted to understand a bit more about the Scala method TraversableLike[A].map whose signature is as follows: def map[B, That](f: A => B)(implicit bf: CanBuildFrom[Repr, B, That]): That Notice a few things about this method: it takes a function turning each A in the traversable into a B i...

Scala 2.8 collections design tutorial

Following on from my breathless confusion, what are some good resources which explain how the new Scala 2.8 collections library has been structured. I'm interested to find some information on how the following fit together: The collection classes/traits themselves (e.g. List, Iterable) Why the Like classes exist (e.g. TraversableLike) ...

scala override methods in child object of class

New to scala and can't seem to find a reference on this situation. I'm trying to override some methods on scala.swing.TabbedPane.pages: The definition of this class is: class TabbedPane extends Component with Publisher { object pages extends BufferWrapper[Page] { def += } } I can't figure out the syntax for overriding any...

Is the Scala 2.8 collections library a case of "the longest suicide note in history" ?

First note the inflammatory subject title is a quotation made about the manifesto of a UK political party in the early 1980s. This question is subjective but it is a genuine question, I've made it CW and I'd like some opinions on the matter. Despite whatever my wife and coworkers keep telling me, I don't think I'm an idiot: I have a goo...

Scala and html: download an image (*.jpg, ect) to Hard drive

Ive got a Scala program that downloads and parses html. I got the links to the image files form the html, Now I need to transfer those images to my hard drive. Im wondering what the best Scala method I should use. my connection code: import java.net._ import java.io._ import _root_.java.io.Reader import org.xml.sax.InputSource import ...

Implicit conversion from String to Int in scala 2.8

Is there something I've got wrong with the following fragment:- object Imp { implicit def string2Int(s: String): Int = s.toInt def f(i: Int) = i def main(args: Array[String]) { val n: Int = f("666") } } I get the following from the 2.8 compiler:- Information:Compilation completed with 1 error and 0 warnings Information:...

Refactoring val to method results in compile-time error

I currently have def list(node: NodeSeq): NodeSeq = { val all = Thing.findAll.flatMap({ thing => bind("thing", chooseTemplate("thing", "entry", node), "desc" -> Text(thing.desc.is), "creator" -> thing.creatorName.getOrElse("UNKNOWN"), "delete" -> SHtml.link("/test", () => delete(thing), Text("delete"...

If the Nothing type is at the bottom of the class hierarchy, why can I not call any conceivable method on it?

The scala type Nothing represents (as I understand it) the bottom of the type hierarchy, also denoted by the symbol ⊥. That is, Nothing is a sub-type of any given type. The requirement for a Nothing type is explained well by James Iry for those of us without a theoretical background in type theory! So my question is, if Nothing is a sub...

Private and protected constructor in Scala

I've been curious about the impact of not having an explicit primary constructor in Scala, just the contents of the class body. In particular I suspect that the private or protected constructor pattern, i.e. controlling construction through the companion object or another class or object's methods might not have an obvious implementati...

Using Scala, how does one differentiate XML elements having elements as children, or having text?

I'm parsing some xml, and given a particular node, I'm trying to figure out which one of these it is: An element with nested elements <theElement><nestedElement>foobar</nestedElement></theElement> An element with text/data in it <theElement>foobar</theElement> I've tried checking the length of Node.text, but Node.text returns "foob...

How to efficiently process 300+ Files concurrently in scala

Hello I'm going to work on comparing around 300 binary files using Scala, bytes-by-bytes, 4MB each. However, judging from what I've already done, processing 15 files at the same time using java.BufferedInputStream tooks me around 90 sec on my machine so I don't think my solution would scale well in terms of large number of files. Ideas...

To use or not to use Scala for new Java projects ?

Hi, I'm impressed with twitter and investigating to use Scala for a new large scale web project with Hibernate and Wicket. What do you think about Scala, and should I use it instead of Java ? EDIT: And, do you think google's Noop, Fan or Scala can take the leadership from Java in the near future, which one have chance in your opinion ? ...

Trying to make sierpinski triangle generator in a functional programming style

I have a function in Scala, and the same function in JavaScript, but I don't think it is in a functional style. def drawSurroundingTriangles(startx : Double, starty : Double, width : Double) { var newwidth = width/2; var newstartx = startx + newwidth / 2; var newstarty = starty - newwidth; drawTriangle(newstartx, newstarty, newwidth...