scala-2.9

converting Akka's Future[A] to Future[Either[Exception,A]]

纵然是瞬间 提交于 2019-11-30 09:49:17
Is there a method in Akka (or in the standard library in Scala 2.10) to convert a Future[A] which might fail into a Future[Either[Exception,A]] ? I know that you can write f.map(Right(_)).recover { case e:Exception => Left(e) } It just seems to be such a common task that I wonder whether I have overlooked something. I'm interested in answers for Scala 2.9/Akka and Scala 2.10. The primary reason why this method is missing is that it does not really have good semantics: the static type Future[Either[Throwable, T]] does not ensure that that future cannot fail, hence the type change does not gain

SBT including the version number in a program

懵懂的女人 提交于 2019-11-30 06:31:51
问题 I want a program I'm building to be able to report its own version at runtime (e.g. scala myprog.jar --version ). Traditionally in a maven project, I'd use resource filtering (pom.xml -> file.properties -> read value at runtime). I know there's sbt-filter-plugin to emulate this functionality, but I'm curious if there's a more standard / preferred / clever way of doing this in SBT. tl;dr how can I read the version number defined in build.sbt at runtime? 回答1: Update... https://github.com

What is the === (triple-equals) operator in Scala Koans?

拜拜、爱过 提交于 2019-11-30 04:10:38
I started working my way through the Scala Koans , which is organized around a suite of unit tests with blanks that one needs to fill in. (This idea was modeled after a similar Ruby Koans project.) You start the sbt tool running a test, and it admonishes: [info] + ***************************************** [info] + [info] + [info] + [info] + Please meditate on koan "None equals None" of suite "AboutEmptyValues" [info] + [info] + [info] + [info] + ***************************************** ...and so you go look at this unit test and it says: test("None equals None") { assert(None === __) } ...and

coin change algorithm in scala using recursion

浪尽此生 提交于 2019-11-29 21:53:50
I am trying to program the coin change problem in Scala using recursion. The code that i have written is as follows. def countChange(money: Int, coins: List[Int]): Int = { def ways(change: List[Int], size: Int, capacity: Int): Int = { if(capacity == 0) 1 if((capacity < 0) || (size <= 0)) 0 //println and readLine to check and control each recursive call. println("calling ways(",change, change.length-1, capacity,") + ways(",change, change.length, capacity - change(change.length - 1),")") readLine() // ways(change, change.length-1, capacity) + ways(change, change.length, capacity - change(change

converting Akka's Future[A] to Future[Either[Exception,A]]

a 夏天 提交于 2019-11-29 14:40:55
问题 Is there a method in Akka (or in the standard library in Scala 2.10) to convert a Future[A] which might fail into a Future[Either[Exception,A]] ? I know that you can write f.map(Right(_)).recover { case e:Exception => Left(e) } It just seems to be such a common task that I wonder whether I have overlooked something. I'm interested in answers for Scala 2.9/Akka and Scala 2.10. 回答1: The primary reason why this method is missing is that it does not really have good semantics: the static type

SBT including the version number in a program

╄→гoц情女王★ 提交于 2019-11-28 19:20:46
I want a program I'm building to be able to report its own version at runtime (e.g. scala myprog.jar --version ). Traditionally in a maven project, I'd use resource filtering (pom.xml -> file.properties -> read value at runtime). I know there's sbt-filter-plugin to emulate this functionality, but I'm curious if there's a more standard / preferred / clever way of doing this in SBT. tl;dr how can I read the version number defined in build.sbt at runtime? Update... https://github.com/ritschwumm/xsbt-reflect (mentioned above) is Obsolete, but there is this cool SBT release tool that can

coin change algorithm in scala using recursion

我是研究僧i 提交于 2019-11-28 17:45:16
问题 I am trying to program the coin change problem in Scala using recursion. The code that i have written is as follows. def countChange(money: Int, coins: List[Int]): Int = { def ways(change: List[Int], size: Int, capacity: Int): Int = { if(capacity == 0) 1 if((capacity < 0) || (size <= 0)) 0 //println and readLine to check and control each recursive call. println("calling ways(",change, change.length-1, capacity,") + ways(",change, change.length, capacity - change(change.length - 1),")")

Scala: write string to file in one statement

99封情书 提交于 2019-11-27 10:24:24
For reading files in Scala, there is Source.fromFile("file.txt").mkString Is there an equivalent and concise way to write a string to file? Most languages support something like that. My favorite is Groovy: def f = new File("file.txt") // Read def s = f.text // Write f.text = "file contents" I'd like to use the code for programs ranging from a single line to a short page of code. Having to use your own library doesn't make sense here. I expect a modern language to let me write something to a file conveniently. There are posts similar to this, but they don't answer my exact question or are

Scala: write string to file in one statement

牧云@^-^@ 提交于 2019-11-26 11:53:03
问题 For reading files in Scala, there is Source.fromFile(\"file.txt\").mkString Is there an equivalent and concise way to write a string to file? Most languages support something like that. My favorite is Groovy: def f = new File(\"file.txt\") // Read def s = f.text // Write f.text = \"file contents\" I\'d like to use the code for programs ranging from a single line to a short page of code. Having to use your own library doesn\'t make sense here. I expect a modern language to let me write