I have a Scala data processing tool which is failing with a java.lang.OutOfMemoryError exception. The tool needs to make a couple passes over a large data file (the one I'm working on is over 700MB), so it would be convenient if the entire thing could be stored in memory.
I run the tool from the command line or from a Bash script using ...
Are there any good Scala blogs you regularly follow?
...
I want to shallow copy a list in Scala.
I wanted to do somehing like:
val myList = List("foo", "bar")
val myListCopy = myList.clone
But the clone method is protected.
...
Let's say I have a class that looks something like this:
class Foo(Prop1:Int, Prop2:Int, Prop3:Int)
{
..
}
And I wanted to create a function that gets the max of some arbitrary property from a list of Foos.
Like this:
def getMax(Foos:List[Foo], Property:??) = Foos.map(_.Property).sort(_ > _).head
If I called getMax(myFooList, Pro...
I just converted the following Java into Scala:
char[] map = new char[64];
int i=0;
for (char c='A'; c<='Z'; c++) map[i++] = c;
for (char c='a'; c<='z'; c++) map[i++] = c;
for (char c='0'; c<='9'; c++) map[i++] = c;
map[i++] = '+';
map[i++] = '/';
My first attempt was an array:
val map1 = (
('A' to 'Z') ++ ('a' to 'z') ++ ('0' to '...
I'm trying to call a 2 parameters function in List.foreach, with the first parameter fixed for a loop. In fact I want to curry a function of two parameters into a function of one parameter which returns a function of one parameter (as List.foldLeft do)
This does not work:
private def mathFunc1(a: Double, b: Double) =
println(a + b)...
I'm following the Lift tutorial and it is referencing to a User object. It doesn't say where it's coming from. I also could not find it in the API. Does anyone know what I have to import to get it?
Here's the sample code with a FK to User in the model:
object owner extends MappedLongForeignKey(this, User)
...
To begin with, I'm virtually sold on the 'whole functional language thing'. It occurs to me that, for years, I've been doing mostly functional-style programming in Java. But I'm a bit loss as to how to start a large functional app. I'd like to see the source and build structure of a large project (OSS or whatever) so that I can see ho...
How do I get the function value f of an instance method?
class X(i : Int){
def method(y : Int) = y + i
}
val x = new X(10)
val f : (Int) => Int = ?
val r = x.method(2)
val r2 = f(2)
Calling x.method(2) and f(2) would be the same method call.
...
I'm developing on the standard Lift platform (maven and jetty). I'm repeatedly (once every couple of days) getting this:
Exception in thread "7048009@qtp-3179125-12" java.lang.OutOfMemoryError: PermGen space
2009-09-15 19:41:38.629::WARN: handle failed
java.lang.OutOfMemoryError: PermGen space
This is in my dev environment. It's not ...
I'm writing a Java application using Struts 2, but now I'd like to make it a hybrid Java & Scala project instead. I don't have much experience with Scala, but I learned Haskell years ago at college -- I really liked the functional programmed paradigm, but of course in class we were only given problems that were supremely suited to a func...
I would like to be able to encrypt files on disk and/or data in memory using GnuPG from a Java application. If possible I'd like to avoid having to make system calls out to the GPG command line tools.
Is there a recommended library, or can you recommend the best approach to GPG encrypting from Java (or Scala)?
I'm developing and inten...
I am looking to write a system which allows a syntax like the following:
a b/c
With a being a class, b being a specific term (not any arbitrary string) and c being an Int.
I realize you can do
a b c
which becomes
a.b(c)
However, the first syntax would be more elegant and any solution would help me expand my scala knowledge :)
...
This is probably simple for someone experienced with it, but this is my first JVM adventure. I just compiled this scala library (per the instructions on that page) and all it appeared to do was give me a bunch of .class files.
What do I have to do to use these in my project? I'm using netbeans if that matters.
...
Here is the POC code:
object TypeTest extends Application {
val stuff = List(1,2,3,4,5)
def joined:String = stuff.reduceLeft(_ + ", " + _)
println(joined)
}
Upon compiling, it gives the following error:
tt.scala:4: error: type mismatch;
found : java.lang.String
required: Int
def joined:String = stuff.reduceLeft(_...
I'm having trouble using jarjar from the command-line to combine a simple Scala program with the scala runtime-library.
jarjar correctly detects the dependency:
$ java -jar ~/Desktop/saug/jarjar-1.0.jar find jar BCT.jar scala-library.jar
/home/schani/Work/scala/bct/BCT.jar -> /home/schani/Work/scala/bct/scala-library.jar
Combining th...
I understand that actors are a great feature and are the #1 choice for concurrency in scala, but I don't know if they would apply here.
I am creating an asynchronous server. Clients connect, send data, the server does a cpu intensive task, and then the client disconnects. There is no waiting for data - as soon as the client connects, it...
In Scala, what's the best way to dynamically instantiate an object and invoke a method using reflection?
I would like to do Scala-equivalent of the following Java code:
Class class = Class.forName("Foo");
Object foo = class.newInstance();
Method method = class.getMethod("hello", null);
method.invoke(foo, null);
In the above code, bot...
In Java you can write Boolean.valueOf(myString). However in Scala, java.lang.Boolean is hidden by scala.Boolean which lacks this function. It's easy enough to switch to using the original Java version of a boolean, but that just doesn't seem right.
So what is the one-line, canonical solution in Scala for extracting "true" from a string?...
Suppose we have the following Java interface:
// Java
public interface Foo {
<T> T bar(Class<T> c);
}
How should I extend it in Scala? Writing
// Scala
class FooString extends Foo {
override def bar(c: Class[String]): String = "hello, world";
}
will cause the compiler to throw "class FooString needs to be abstract, since meth...