scala

How to write (String): Int function?

I'd like to convert an Array[String] to an Array[Int], using map method. What is the shortest way to get a function of type (String) => Int to pass as map argument? I'd prefer convert existing builtin ones like Integer.valueOf in some way. A method of argument binding to shorten the construction like def parseInt(s:String) = Integer.par...

How to ignore exception?

Is there more elegant way to write: try { ... // Some throwing code return first } catch { case e:ExceptionType => {} // No code to execute. Ignore error. } return second ...

Redirecting to search params in lift

I have a search box that sends an ajax request to a snippet. When the snipped function gets called I would like the search query to get added to the URL via a anchor hash (ala: http://localhost/search#param) so I can recreate the search request if the user copies the URL and comes back later. Obviously the other side to this is pulling t...

"MyType" problem: Do I have to use abstract types (or generics) in Scala to return the actual class?

I am not sure if there is a better way of doing this: trait Animal { val name: String val weight: Int type SubAnimal <: Animal def updateName(n: String) = returnMe(n, this.weight) def updateWeight(w: Int) = returnMe(this.name, w) // Abstract protected method protected def returnMe(n: String, w: Int): SubAnimal } case cl...

Question about Scala implicit conversions Non-Ambiguity Rule

Hello. Could anybody explain me following situation with Scala implicit conversions mechanism. There is a code: object Main { implicit val x:Int => String = v => "val" implicit def y(v:Int) = "def" def p(s:String) = print(s) def main(args: Array[String]): Unit = { p(1) } } This code prints "val". But when I comment ...

scala overriding None

My first Scala program and I am stuck. So basically i am trying to override the potential None value of "last" to a 0l in the declaration of past. import java.util.Date; object TimeUtil { var timerM = Map( "" -> new Date().getTime() ); def timeit(seq:String, comment:String) { val last = timerM.get(seq) val cu...

Memory barriers and coding style over a Java VM

Suppose I have a static complex object that gets periodically updated by a pool of threads, and read more or less continually in a long-running thread. The object itself is always immutable and reflects the most recent state of something. class Foo() { int a, b; } static Foo theFoo; void updateFoo(int newA, int newB) { f = new Foo(); ...

Databases non-ORM and Scala

What is the best non-ORM database to work with Scala? I find this link link text, but this does not answer my question fully. Could be considered desirable features performance, scalability and facility to write complex structures of relationships between data. Thanks ...

Bit fields in Scala

How to simulate bit fields in Scala? The bit fields are used to access some bits of one type (like this in C link). I know it's possible to write with bit operators, but I think there a better way if not consider the performance. Thanks for every hint that might give. ...

i want my popup window to appear in center.

Hi everybody.i had created my popup window which is appearing on a click of link but it is coming at the top corner of window and want it to appear it in at center and also want to resize it. i had created it in scala and calling it with html file.so everybody please give your suggetions as fast as possible. ...

Migrating Java to Scala

What are the most important points to be aware of, and the workarounds, when gradually migrating an existing Java codebase to Scala? With a (potentially very long) intermediate phase where both languages are in use. The sort of things I'm thinking about are: different collection hierarchies Java constructs that Scala can't handle wel...

How to get a reference to a Lift MetaMapper object by name?

In modeling an audit table, I've included fields necessary to find the original record being audited (oid: String, className: String). I'd like to programmatically find the MetaMapper for the Mapper class name. For example, if I have: class Foo extends Mapper[Foo] { def getSingleton = Foo } object Foo extends Foo with MetaMapper[Fo...

Using simple-build-tool for benchmarks

I'm trying to get sbt to compile and build some benchmarks. I've told it to add the benchmarks to the test path so they're recompiled along with tests, but I can't figure out how to write an action to let me actually run them. Is it possible to invoke classes from the Project definition class, or even just from the command line? ...

Missing members from default constructor arguments

The following class has an auxillary constructor to change one property in an immutable way. class AccUnit(size: Long, start: Date, direction:Direction, protocol:String) { def this(size:Long, that:AccUnit) {this(size, that.start, that.direction, that.protocol)} } Compiler returns an errors: AccUnit.scala:26: error: value start is...

Code Optimization with Scala

What structures of Scala can be used more efficiently than in Java, to increase execution speed? I don't know if this is possible, but to clear my doubts :) Thanks ...

What could make this dsl easier to type or read?

I've written a working grammar to replace dbunit in scala called ScalaDBTest. The whole program works - only took 2 days to write. I got a lot of polishing to do. Anyway, the grammar I'm using for the DSL to input data into the database is malleable and I'd like some feedback on it. The basic syntax looks like this. It's pretty simple...

Why can't python infer types like scala ?

Possible Duplicate: How to deal with Python ~ static typing? I'm basically a Java programmer with little knowledge of python.I really like the syntax of python and the ease with which a programmer is able to express his idea's but also I'm aware that python is dynamically typed and thus is not as fast as Java.My question is wh...

Overhead of "boxing" primitive types via implicits in Scala

Suppose I want to have a class like Java Date. Its only data member is a long which represents the milliseconds since 1970. Would/Could it be of any performance benefit of just making a new Scala type: type PrimitiveDate = Long Then you can add methods by using implicit conversion, like it is done for int with RichInt. Does this "box...

Scala naming convention for "setters" on immutable objets

I do not know what to call my "setters" on immutable objects? For a mutable object Person, setters work like this: class Person(private var _name: String) { def name = "Mr " + _name def name_=(newName: String) { _name = newName } } val p = new Person("Olle") println("Hi "+ p.name) p.name = "Pelle" println("Hi "+ p.name) Th...

convert unparameterized Java 1.4 Collection to parameterized Scala Sequence

How can I convert a java 1.4 Collection to a Scala Seq? I am trying to pass a java-collection to a scala method: import scala.collection.JavaConversions._ // list is a 1.4 java.util.ArrayList // repository.getDir is Java legacy code val list = repository.getDir(...) perform(list) def perform(entries: List[SVNDirEntry]) = ... I alwa...