scala

How to use dispatch.json in lift project

i am confused on how to combine the json library in dispatch and lift to parse my json response. I am apparently a scala newbie. I have written this code : val status = { val httpPackage = http(Status(screenName).timeline) val json1 = httpPackage json1 } Now i am stuck on how to parse the twitter json r...

Develop a Scala/Lift Web App using Eclipse and Tomcat

So I have spent the past 11 hours now trying to get even the simplest Scala/Lift app to run on Tomcat through Eclipse. Apparently no one is trying to do this or it is the easiest thing in the world so no one has documented how they did it. Creating the code using a maven archetype and running it with mvn tomcat:run is no problem. Making ...

Why is the result different for a tiny change regarding abstract trait member val initialization?

I got the following code snippet referring an example in Chapter 6 of "Programming Scala": object HelloWorld { def main(args: Array[String]) { trait AbstractT2 { println("In AbstractT2:") val value: Int val inverse = 1.0 / value // ??? println("AbstractT2: value = " + value + ", inverse = " + inverse) }...

Ways to improve this code

I am trying to write some test code for my java application using Scalatest. I figured, since Scala has so much more readable syntax it would result with more readable test code. So far, this is what I managed: package com.xyz import org.scalatest.FlatSpec import org.scalatest.matchers.ShouldMatchers import com.xyz.SecurityService ...

Scala: why does this code need an empty line or a semicolon?

package it.onof.scalaDemo case class MyInt(val i : Int) { private def factorial(a : Int) : Int = a match { case 0 => 1 case n => (n) * factorial(n-1) } def ! = factorial(i) override def toString = i.toString } object MyInt { implicit def intToMyInt(x : Int) = MyInt(x) implicit def myIntToInt(x : ...

Error inserting document into mongodb from scala

Trying to insert into a mongodb database from scala. the below codes dont create a db or collection. tried using the default test db too. how do i perform CRUD operations? object Store { def main(args: Array[String]) = { def addMongo(): Unit = { var mongo = new Mongo() var db = mongo.getDB("mybd") ...

Why is my algorithm for Project Euler Problem 12 so slow?

Hi, I have created solution for PE P12 in Scala but is very very slow. Can somebody can tell me why? How to optimize this? calculateDevisors() - naive approach and calculateNumberOfDivisors() - divisor function has the same speed :/ import annotation.tailrec def isPrime(number: Int): Boolean = { if (number < 2 || (number != 2 && num...

Why doesn't the Array Equality Function Work as Expected?

In Programming in Scala the authors write that Scala's == function compares value equality instead of reference equality. This works as expected on lists: scala> List(1,2) == List(1,2) res0: Boolean = true It doesn't however work on arrays: scala> Array(1,2) == Array(1,2) res1: Boolean = false In Programming Scala the authors reco...

Why does Scala require a return type for recursive functions?

In the code snippet included below, I have a recursive function call, used to facilitate a retry if a network call fails (Amazon SimpleDB will occasionally return a 503 and require retry.) When I try to compile, the Scala complains recursive method simpledb_update needs result type. // sends data to SimpleDB. Retries if necessary def...

Where can I download Scala source jars (scala-library-src.jar etc.)

I am trying to use IntelliJ Idea Scala plugin, but it says it wants scala-library-src.jar, scala-swing-src.jar, scala-dbc-src.jar. Where can I download these files? I use Scala 2.8. ...

Scala analogues of QtConcurrent

Hello! What are the analogues of QtConcurrent for Scala (or Java)? Ie simplified implementation of MapReduce, the parallel map and foldl. Thank you ...

What ways to perform CRUD operations in Scala with mongoDB

Hi, what are the methods/drivers i can use to perform CRUD operations? Atm, i am only successful with the Create function, ie DBObbject.put("field","value") Common sense suggests that find() should stand for retrieve, but using it gives the following error value find is not a member of com.mongodb.BasicDBObject All and any help ap...

Idiomatic Scala

I'm trying to get my Scala code to be a bit more idiomatic. Right now it just looks like Java code. I'm trying to do a simple boolean regex matching function in Scala, since I cannot seem to find it in the standard library(?) I don't think the result is particularly nice with the try-catch and all. Also, a precondition is that 'patt' h...

How to make Scala Power Pack for IntelliJ Idea to work?

I've installed Scala, SBT and Scala Power Pack plugins for IntelliJ Idea 9. And it says "Plugin scala power pack failed to initialize and will be disabled: scala/collection/VectorLike Please restart IntelliJ IDEA" I've found this with Google but with no solution. Do you know one? ...

What type to use to store a single char in Scala?

I am writing a function which is meant to take a character as an argument and return a character. Using String for this looks a bit strange for me. Should I, or there is something like a char type in Scala 2.8? ...

Scala Type inference for anonymous function declaration

Hi all, I'm a beginner in Scala and I'm just curious about how Scala handles the type inference for this code snippet trait Expression { .... } def eval (binding : String => Boolean) : Expression => Boolean I understand that binding is a function that converts String to Boolean, but why binding at the same time could be declared as ...

Editor does not contain main type

Hello, first of all, i like to say that i have read the other two questions regarding the same problem, and the solutions outlined in them did not help me. i tried cleaning, rebuilding, re-opening but it ddnt work out. I use eclipse for scala dev. This is the sample prog that i am trying to get an output from, its just casbah. package c...

two type parameters with the same name

I am wondering why the two type parameters (named "A") with the same name ("A") is allowed as per the example below. I know this is a POOR naming of type parameters, don't do this. (My guess is that they are on a on a different scope level, e.g. class level and function level, and the compiler is using some kind of name mangling) clas...

Hiding non-java classes from findbugs

I have a mixed scala/java project - mostly java. I would like to use Findbugs on my java code, but the scala classes are giving it trouble. So I'd like to exclude them from Findbugs. So far I've tried listing the scala classes in an exclude filter, but that's not helping. I'm using the maven codehaus findbugs plugin version 2.3.1. The e...

Improve sbt doc generation

When I run sbt doc, it results in a nice but nonetheless pretty basic documentation. Is it possible to a) include the source files for the class definition and b) inherit the docstrings for inherited members? What do I need to add to my project definition? (It’s a Lift project, so most important would be to have the inherited Lift d...