scala-2.8 Questions
2
Solved
what is wrong in this piece of code?
(Left("aoeu")) match{case Right(x) => ; case Left(x) => }
<console>:6: error: constructor cannot be instantiated to expected type;
found : Right[A,B]
req...
Housefather asked 13/12, 2010 at 19:35
3
Solved
Again, this seems like something that should be obvious.
I would like to insert an element into a linked list at a specific position.
In one case, this is where a field in the element is less than ...
Floozy asked 12/12, 2010 at 20:56
2
Solved
I have a feeling I'm missing something very obvious here.
I'm converting a compiler generator written in Java into Scala as a learning exercise.
It's not really written in Java, it seems to be tr...
Oxpecker asked 12/12, 2010 at 11:30
2
Solved
I have a ListBuffer. I want to remove all elements that meet a certain condition.
I could iterate over it and remove each element. But what doe Scala say about mutating a list that you are iterati...
Monteith asked 11/12, 2010 at 17:34
2
Solved
What should ",7-6-5-4-3-2-1,".split(',') return?
It seems to return
blank string
7-6-5-4-3-2-1
ie. two strings. I'd expect either one or three strings - that is a blank string at both ends o...
1
Solved
scala noob here, i have a collection (Seq) of xml nodes, and i would like to populate an Array based on each node:
val nodes = data.child \\"package"
var packages = new Array[Package](nodes.length...
Phosphoresce asked 2/12, 2010 at 16:21
4
Solved
I've a three-level data structure (indentation and line breaks for readability):
scala> import scala.collection.mutable.Map
import scala.collection.mutable.Map
scala> val m = Map("normal" -...
Hercegovina asked 1/12, 2010 at 12:55
3
Solved
in Scala 2.8 when I start actors, I can communicate via message passing. This in turn means that I can send the ultimate Exit() message or whatever I decide fits my protocol.
But how will I check i...
Electrocautery asked 28/11, 2010 at 15:53
6
Solved
I'll start the ball rolling.
Given a sequence of elements, some of which can be contained multiple times, one typical requirement is to count them - in the form of a tally or histogram.
The oft-q...
Unicef asked 25/11, 2010 at 12:22
3
Solved
In C++ I can do the following:
template<typename T, typename V>
struct{
void operator()(T _1, V _2){
_2.foo( _1 );
}
};
which lets me arbitrarily decide to use any object which has some...
4
Solved
How do you use Map.foldLeft? According to the docs it looks like
foldLeft [B] (z: B)(op: (B, (A, B)) ⇒ B) : B
But I'm having difficulty:
Map("first"->1,"second"->2).foldLeft(0)((a,(k,v))...
Hydrolysis asked 14/11, 2010 at 17:34
1
Solved
I'm experiencing an odd bit of behavior when I use the auto-generated copy() method that was added in Scala-2.8.
From what I've read, when you declare a given class as a case-class, a lot of thing...
Tungstate asked 13/11, 2010 at 20:24
3
Solved
I'm still learning Scala, but one thing I thought was interesting is that Scala blurs the line between methods and fields. For instance, I can build a class like this...
class MutableNumber(var va...
Lewan asked 11/11, 2010 at 20:20
1
Solved
I'm working on a simple web application with Scala. The plan is to obtain JSON data from an external API, and insert it into a template (unfortunately, obtaining the data in XML is not an option).
...
Regnal asked 12/11, 2010 at 21:24
3
Solved
This is using Scala 2.8 Actors. I have a long running job which can be parallelized. It consists of about 650,000 units of work. I divide it into 2600 different separate subtasks, and for each of t...
Wept asked 8/11, 2010 at 20:22
3
Solved
scala> class Foo[T <: Comparable[T]](val x : T)
defined class Foo
scala> (3: Int).asInstanceOf[Comparable[Int]]
res60: java.lang.Comparable[Int] = 3
scala> new Foo(3)
<console>...
1
Solved
This is something I've wondered about for a while. I see this pattern a lot:
if (pf.isDefinedAt(in)) pf(in)
By breaking this up into two separate calls, all of the patterns that were evaluated i...
Amphibole asked 31/10, 2010 at 20:0
2
Solved
I've created a class that can be parameterised by anything that can be converted to Numeric
class Complex[T <% Numeric[T]] (val real : T, val imag : T) {
//... complex number methods ...
}
T...
6
Solved
In Rails, one could use:
returning Person.create do |p|
p.first_name = "Collin"
p.last_name = "VanDyck"
end
Avoiding having to do this:
person = Person.create
person.first_name = "Collin"
per...
Touching asked 22/10, 2010 at 12:51
1
Solved
Even with the prevalence of the Box and Option monads, we still have to check for null values here and there. The best I've come up with so far is by using the Box#!! method:
(Box !! possiblyNull)...
2
Solved
Although I've been using Scala for a while and have mixed it with Java before, I bumped on a problem.
How can I pass a Java array to Scala? I know that the other way around is fairly straightforwa...
2
Solved
sealed abstract trait HList
case class :+:[H, T <: HList](head: H, tail: T) extends HList {
def :+:[T](v: T) = new :+:(v, this)
}
case object HNil extends HList {
def :+:[T](v: T) = new :+:(...
2
Solved
I just found it in the API and would like to see one or two examples along with an explanation what it is good for.
3
I have reached this far:
implicit def collectionExtras[A](xs: Iterable[A]) = new {
def zipWith[B, C, That](ys: Iterable[B])(f: (A, B) => C)(implicit cbf: CanBuildFrom[Iterable[A], C, That]) = ...
Plasmolysis asked 9/10, 2010 at 5:14
1
Help,
how do i do stuff like the following in Scala?
import org.hibernate.validator.constraints.ScriptAssert
@ScriptAssert.List({
@ScriptAssert(script = "...", lang = "javascript"),
@ScriptAss...
Permanency asked 30/9, 2010 at 1:58
© 2022 - 2024 — McMap. All rights reserved.