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...
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
...
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...
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...
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 ...
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...
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();
...
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
...
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.
...
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.
...
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...
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...
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?
...
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...
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
...
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...
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...
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...
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...
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...