Hi scala gurus
Can anyone re-write this code to do the same thing but without any compiler warnings please:-
object TestTypeErasure {
def main(args:Array[String]) {
def myFunction(myObject:Any):Boolean = {
true
}
val myVariable: (Any => Boolean) = myFunction
myVariable match {
case function:(Any => Boo...
Hello StackOverflow,
I have problems with writing an specific application in a scala-esque and elegant way. I tried this for some time now, but I cannot find a "good" solution to this Problem:
Given that I have the following List:
List("foo", "bar", "baz", "blah")
I want to Iterate over this list, not only giving me the current elem...
What must I do in order to be able to return an Iterator from a method/class ? How would one add that trait to a class?
...
I am converting some Java NIO code to run in Scala and I am getting an error because the SelectionKey I'm calling returns a SelectableChannel rather than a DatagramChannel, which is a subclass of SelectableChannel and an instance of which I declare at the beginning of the code. I did not come to Scala from Java, so my knowledge of Java i...
I'm looking for a well documented open source project, written in scala to
see best practices etc.
At sourceforge.net I found a few projects tagged as scala
but they were actually written in java.
github seems a bit better:
http://groups.google.com/group/scala-melb/web/open-scala-projects
Does anyone know such a project which could be...
Is it possible to implement in Scala something equivalent to the python yield statement where it remembers the local state of the function where it is used and "yields" the next value each time it is called?
I wanted to have something like this to convert a recursive function into an iterator. Sort of like this:
# this is python
def fo...
I've come up with this implementation of groupBy:
object Whatever
{
def groupBy[T](in:Seq[T],p:T=>Boolean) : Map[Boolean,List[T]] = {
var result = Map[Boolean,List[T]]()
in.foreach(i => {
val res = p(i)
var existing = List[T]() // how else could I declare the reference here? If I write var exi...
I'm going to give a talk about using Java and Scala together and I want to investigate some projects (large and small) which contains Java and Scala code.
If you know links to correspondent projects post them here.
...
I'm working on a Scala project that is importing two java libraries. Through poor planning, the two java libraries have similar package names, one with com on the front, one without.
The problem is that Scala is looking for the package with com in front first, and telling me that the package doesn't exist. If I remove all references t...
I'm trying to mock a method call that takes a call-by-name argument:
import org.scalatest.WordSpec
import org.scalatest.mock.MockitoSugar
import org.mockito.Mockito._
import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner
trait Collaborator {
def doSomething(t: => Thing)
}
trait Thing
@RunWith(classOf[JUnitRunner])...
There are a few cases of source incompatibilities with Scala 2.8.0. For example, creating an anonymous Seq once required defining the abstract def elements : Iterator[A], which is now called def iterator : Iterator[A].
To me, a "brute force" solution is to create two branches that align to the different major scala versions.
Are there ...
I have a piece of code that I use to provide an implicit ordering for a priority queue:
type Time = Int
type Item = (Time, Whatever)
implicit def order(thisItem: Item): Ordered[Item] =
new Ordered[Item] {
override def compare(thatItem: Item) = {
val result = thisItem._1 compareTo thatItem._1
-result
}
...
I can implement a def with a val where the def takes no arguments:
trait T { def foo: Int }
class C(val foo: Int) extends T
Why can this not be extended to implementing a def taking N args to a val which is a FunctionN? I want it possible to implement something like:
def expensiveOperation(p: Int => Boolean) : List[Int]
With a lazy...
Since Scala has so many cool stuff I was thinking it may have something that makes capturing a process's output easy. I know the Java way of doing that, but I thought about asking for another way.
...
Can anyone explain the compile error below? Interestingly, if I change the return type of the get() method to String, the code compiles just fine. Note that the thenReturn method has two overloads: a unary method and a varargs method that takes at least one argument. It seems to me that if the invocation is ambiguous here, then it wou...
Is there any scala JSP engine, or is there going to be any?
i know about the scala web framework lift, but it seems more like tags.
i am looking for a way to script like PHP.
thanks.
...
I come from a Python background, where at any point in my code I can add
import pdb; pdb.set_trace()
and at runtime I'll be dropped into an interactive interpreter at that spot. Is there an equivalent for scala, or is this not possible at runtime?
...
I'm trying to convert a project over to scala 2.8 from 2.7 and I've run into some difficulty in the code that interacts with Java. Below is a slightly convoluted piece of sample code displaying the problem. Essentially I have class with a member variable of type mutable.Map[K,V] and I can't find a way to pass that through to a method tha...
Dear All,
I have the following code for building a cache using google collections:
val cache = new MapMaker().softValues().expiration(30,
TimeUnit.DAYS).makeComputingMap(
new com.google.common.base.Function[String,Int] {
def apply(key:String):Int ={
1
}
})
And I am getting the following error message:
error:...
Hi everybody,
I'm creating a small application for my company in Lift. I'm quite a newbie in Scala/Lift so I'm using this chance to practice. Now, I have a question on what ORM system to use.
On one hand, Mapper is the Lift default. On the other hand, I've read it's not good in certain areas and will be replaced by Record (which is not...