scala-2.8

How do I implement a collection in Scala 2.8?

爱⌒轻易说出口 提交于 2019-12-03 16:21:59
问题 In trying to write an API I'm struggling with Scala's collections in 2.8(.0-beta1). Basically what I need is to write something that: adds functionality to immutable sets of a certain type where all methods like filter and map return a collection of the same type without having to override everything (which is why I went for 2.8 in the first place) where all collections you gain through those methods are constructed with the same parameters the original collection had (similar to how

How to split and dispatch an async control-flow using Continuations?

我们两清 提交于 2019-12-03 12:50:50
问题 I have an asynchronous control-flow like the following: ActorA ! DoA(dataA, callback1, callbackOnErrorA) def callback1() = { ... ActorB ! DoB(dataB, callback2, callbackOnErrorB) } def callback2() = { ActorC ! DoC(dataC, callback3, callbackOnErrorC) } ... How would I divide this flow into several parts (continuations) and sequentially dispatch these to different actors (or threads/tasks) while maintaining the overall state? Any hint appreciated, Thanks 回答1: This is very simplified, but shows

Mixing Scala and Java files in an Eclipse project

只谈情不闲聊 提交于 2019-12-03 12:04:29
问题 I'm probably doing something stupid, but I can't spot it. I've installed Eclipse Helios (Helios because I couldn't get Glassfish support to work correctly using Gallileo) and the nightly build of the Scala Eclipse plugin for Helios I've created a Scala project and added some files - a mix of Java and Scala. They all seem syntactically correct - the Eclipse editor at least seems to know what language each file is, and reports correctly on syntax errors when I make them - but the Java files

Writing functions of tuples conveniently in Scala

梦想与她 提交于 2019-12-03 10:45:47
问题 Quite a few functions on Map take a function on a key-value tuple as the argument. E.g. def foreach(f: ((A, B)) ⇒ Unit): Unit . So I looked for a short way to write an argument to foreach : > val map = Map(1 -> 2, 3 -> 4) map: scala.collection.immutable.Map[Int,Int] = Map(1 -> 2, 3 -> 4) > map.foreach((k, v) => println(k)) error: wrong number of parameters; expected = 1 map.foreach((k, v) => println(k)) ^ > map.foreach({(k, v) => println(k)}) error: wrong number of parameters; expected = 1

Targeting Android with Scala 2.8 Trunk builds

别来无恙 提交于 2019-12-03 10:41:08
The definitive reference for using Scala on android seems to be here: http://www.scala-lang.org/node/160 Unfortunately, all the references on using scala with android are based around Scala 2.7 and refer to a custom build android-library.jar, with a couple of cryptic references suggesting that this custom build isn't needed for later versions of android (I'm using 2.1 / API v7) So... What are the steps needed to use Scala 2.8 in an android project? Preferably using eclipse and the Android tools that Google supplies for that IDE. Edit: My new way of doing this is to use my Eclipse plugin: https

In Scala 2.8 collections, why was the Traversable type added above Iterable?

筅森魡賤 提交于 2019-12-03 09:58:18
I know that to be Traversable , you need only have a foreach method. Iterable requires an iterator method. Both the Scala 2.8 collections SID and the "Fighting Bitrot with Types" paper are basically silent on the subject of why Traversable was added. The SID only says "David McIver... proposed Traversable as a generalization of Iterable." I have vaguely gathered from discussions on IRC that it has to do with reclaiming resources when traversal of a collection terminates? The following is probably related to my question. There are some odd-looking function definitions in TraversableLike.scala ,

What compromises Scala made to run on JVM?

最后都变了- 提交于 2019-12-03 09:46:14
Scala is a wonderful language, but I wonder how could be improved if it had it's own runtime? I.e. what design choices were made because of JVM choice? This article is a discussion with Martin Odersky (Scala's creator) and includes the compromises that were made in Scala for compatibility with Java. The article mentions: Static overloading of methods Having both traits and classes Inclusion of null pointers. VonC The two most important compromises I know about are: type erasure (" reflecting on Type "): It has to manage a Manifest to get around the Java compilation (independent of the JVM, for

How to write a zipWith method that returns the same type of collection as those passed to it?

帅比萌擦擦* 提交于 2019-12-03 09:26:41
问题 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]) = { val builder = cbf(xs.repr) val (i, j) = (xs.iterator, ys.iterator) while(i.hasNext && j.hasNext) { builder += f(i.next, j.next) } builder.result } } // collectionExtras: [A](xs: Iterable[A])java.lang.Object{def zipWith[B,C,That](ys: Iterable[B])(f: (A, B) => C)(implicit cbf: scala.collection.generic

Scala 2.8 TreeMap and custom Ordering

為{幸葍}努か 提交于 2019-12-03 07:34:08
I'm switching from scala 2.7 and ordered to scala 2.8 and using ordering. It looks quite straight forward but I was wondering could I make it a little less verbose. For example: scala> case class A(i: Int) defined class A scala> object A extends Ordering[A] { def compare(o1: A, o2: A) = o1.i - o2.i} defined module A If I then try to create a TreeMap I get an error scala> new collection.immutable.TreeMap[A, String]() <console>:10: error: could not find implicit value for parameter ordering: Ordering[A] new collection.immutable.TreeMap[A, String]() ^ However if I explicitly specify the object A

In Scala, is there a way to take convert two lists into a Map?

独自空忆成欢 提交于 2019-12-03 06:42:28
问题 I have a two lists, a List[A] and a List[B] . What I want is a Map[A,B] but I want the semantics of zip . So started out like so: var tuplesOfAB = listOfA zip listOfB Now I'm not sure how to construct a Map from my tuplesOfAB . As a follow-up question, I also want to invert my map so that from a Map[A,B] I can create a Map[B,A] . Can anyone hit me with a clue-stick? 回答1: In 2.8 this is really simple using the CanBuildFrom functionality (as described by Daniel) and using breakOut with a type