scala

How would one do dependency injection in scala?

I'm still at the beginning in learning scala in addition to java and i didn't get it how is one supposed to do DI there? can or should i use an existing DI library, should it be done manually or is there another way? ...

Simple Scala actor question

I'm sure this is a very simple question, but embarrassed to say I can't get my head around it: I have a list of values in Scala. I would like to use use actors to make some (external) calls with each value, in parallel. I would like to wait until all values have been processed, and then proceed. There's no shared values being modified...

What are the features of dynamic languages (like Ruby or Clojure) which you are missing in Scala?

What do you lose in practice when you choose a statically-typed language such as Scala (or F#, Haskell, C#) instead of dynamically-typed ones like Ruby, Python, Clojure, Groovy (which has macros or runtime metaprogramming capabilities)? Please consider best statically-typed languages and best (in your opinion) dynamically-typed languages...

Do Scala and Erlang use green threads?

I've been reading a lot about how Scala and Erlang does lightweight threads and their concurrency model (actors). However, I have my doubts. Do Scala and Erlang use an approach similar to the old thread model used by Java (green threads) ? For example, suppose that there is a machine with 2 cores, so the Scala/Erlang environment will ...

Convert a List of Options to an Option of List using Scalaz

I want to transform a List[Option[T]] into a Option[List[T]]. The signature type of the function is def lo2ol[T](lo: List[Option[T]]): Option[List[T]] The expected behavior is to map a list that contains only Somes into a Some containing a list of the elements inside the elements Some's. On the other hand, if the input list has at lea...

How to change attribute on Scala XML Element

I have an XML file that I would like to map some attributes of in with a script. For example: <a> <b attr1 = "100" attr2 = "50"/> </a> might have attributes scaled by a factor of two: <a> <b attr1 = "200" attr2 = "100"/> </a> This page has a suggestion for adding attributes but doesn't detail a way to map a current attribute w...

Modern alternatives to Java

I have been a Java developer for 14 years and have written an enterprise-level (~500 kloc) Swing application that uses most of the standard library APIs. Recently, I have become disappointed with the progress that the language has made to "modernize" itself, and am looking for an alternative for ongoing development. I have considered mo...

Remove redundant entries, scala way

Edit: Added the fact, that the list is sorted, and realizing 'duplicate' is misleading, replaced that with 'redundant' in the title. I have a sorted list of entries stating a production value in a given interval. Entries stating the exact same value at a later time adds no information and can safely be left out. case class Entry(minute...

What type of webapp is the sweet spot for Scala's Lift framework?

What kind of applications are the sweet spot for Scala's lift web framework. My requirements: Ease of development and maintainability Ready for production purposes. i.e. good active online community, regular patches and updates for security and performance fixes etc. Framework should survive a few years. I don't want to write a app in...

Why is Scala very complex?

I am a student. I learned java during the 2nd year. Now i am in fourth year. I got bored with java and i started to learn Scala. As i learn it, i find it being very complex (although i love it). My question may apply to all new complex language. Why scala is complex? is it because we need to create complex softwares? or i am the only on...

Transient collections for Scala?

Clojure has a very nice concept of transient collections. Is there a library providing those for Scala (or F#)? ...

How do I set up Scala plugin for NetBeans to copy the Scala runtime library?

Versions: NetBeans 6.8, Scala Kit 0.16.1 When I compile my project, I get the following output: init: deps-jar: Compiling 2 source files to F:\MyProgramming\NorvigSpellChecker\build\classes compile: Created dir: F:\MyProgramming\NorvigSpellChecker\dist Building jar: F:\MyProgramming\NorvigSpellChecker\dist\NorvigSpellChecker.jar Not co...

Scala: Can I nudge a combinator parser to be locally greedy?

Suppose I have an ambiguous language expressed in combinator parser. Is there a way to make certain expressions locally greedy? Here's an example of what I mean. import scala.util.parsing.combinator._ object Example extends JavaTokenParsers { def obj: Parser[Any] = (shortchain | longchain) ~ anyrep def longchain: Parser[Any] = zer...

Common practice for higher-order-polymorphism in scala

Hi, I'm trying to grasp higher-order-polymophism in scala by implementing a very basic interface that describes a monad but I come across a problem that I don't really understand. I implemented the same with C++ and the code looks like this: #include <iostream> template <typename T> class Value { private: T value; public: Value(c...

Scala for Junior Programmers?

Hi, we are considering Scala for a new Project within our company. We have some Junior Programmers with only PHP knowledge, and we are in doubt that they can handle Scala. What are your opinions? Some say: "Scala is a complicated beast!", some say: "It's easy once you got it." Maybe someone has real-world experience? ...

short way to breakOut to specific collection type?

scala> val m = Map(1 -> 2) m: scala.collection.immutable.Map[Int,Int] = Map(1 -> 2) scala> m.map{case (a, b) => (a+ 1, a+2, a+3)} res42: scala.collection.immutable.Iterable[(Int, Int, Int)] = List((2,3,4)) What I want is for the result type to be List[(Int, Int, Int)]. The only way I found is: scala> m.map{case (a, b) => (a+ 1, a+2...

Scala passing type parameters to object

In Scala v 2.7.7 I have a file with class Something[T] extends Other object Something extends OtherConstructor[Something] This throws the error: class Something takes type parameters object Something extends OtherConstructor[Something] { However, I can't do this object Something[T] extends OtherConstructor[Something[T]] I...

Emulating variadic templates in Scala

Suppose you want to have something like variadic templates (the ability to define n type parameters for a generic class) in Scala. For example you do not want to define Tuple2[+T1, +T2] and Tuple3[+T1, +T2, +T3] but Tuple[T*]. Are there other options than HLists that would support Tuple, Product and Function? ...

using REST webservices as a datasource for Lift ?

Is there a way to use a webservice (REST in this case) as the data source for a Lift application? I can find a number of tutorials/examples of using Lift to provide the REST API, but in my case the data is hosted elsewhere and exported as a REST webservice. Pointers to doc are greatly appreciated. Thanks, Jeff ...

Zip elements with odd and even indices in a list

I want to zip even and odd elements in a list to make a list of pairs, like that: ["A", "B", "C", "D", "E", "F"] -> [("A", "B"), ("C", "D"), ("E", "F")] What is the most concise expression to do this in elegant in functional way? ...