scala

Extending an object with a trait which needs implicit member

拥有回忆 提交于 2021-01-29 06:17:51
问题 I'm trying to have a code like below: object MetaData extends CacheParams{} So, since CacheParams needs implicit val p:Parameters , I tried: object MetaData (implicit val p: Parameters) extends CacheParams But it seems that I can't pass arguments to an object. ( because it gives error: traits or objects may not have parameters ) And if I don't pass any arguments it will give compile error that: [error]: object creation impossible, since value p in trait CacheParams of type Parameters is not

project folder in sbt

走远了吗. 提交于 2021-01-29 06:10:59
问题 I understand that in an sbt project, sbt generates a folder called project containing build.properties and plugins.sbt . Now if I have one project that has multi subprojects, should I have only one folder called project in the root project or different folders named project foreach subproject? 回答1: You should have only one project folder. You can read about it at Multi-project builds in sbt documentation. For example, to the following sbt: name := "new_proj" version := "0.1" scalaVersion :=

Scala spark: Create List of Dataset from a Dataset map operation

旧巷老猫 提交于 2021-01-29 05:42:35
问题 Suppose I want to create 2 types of metric : metricA or metricB after transforming another dataset. If a certain condition is met, it'll generate both metricA and B, if condition is not met, generate only metric A. The idea is to write the 2 metrics to 2 different paths (pathA, pathB). The approach I took was to create a Dataset of GeneralMetric and then based on whats inside, write to different paths, but obviously it didn't work as pattern matching inside Dataset wouldn't work val s:

Why does this command behave differently depending on whether it's called from terminal.app or a scala program?

感情迁移 提交于 2021-01-29 05:39:22
问题 So I'm working on extracting a file.cbz to display it's contents. I was hoping to go about it with the following code: println("7z x -y \"" + filePath + "\"" + s" -o$tempLocation") if (("7z x -y \"" + filePath + "\"" + s" -o$tempLocation").! == 0){ //I would have liked to do the whole thing with string interpolation, but I didn't work. Seems to be this bug https://issues.scala-lang.org/browse/SI-6476 Some(new File(tempLocation)) }else{ println("Something went wrong extracting the file,

How to use fetchNewObject with update.one ReactiveMongo?

不想你离开。 提交于 2021-01-29 05:14:26
问题 Previously I used findAndUpdate and could add fetchNewObject = true so I was able to do something like this after the query: .map(_.result[WhicherReport].getOrElse { throw new NoSuchElementException }) but I'm using transaction now and could only perform update.one(...) and there is no option to pass it fetchNewObject , what can I do? This is my func: def someUpdateFunc(collection: BSONCollection, metadata: Metadata, ids: List[String]): Future[UpdateWriteResult] = { collection.update.one( q =

sbt run/debug configuration broken showing unknown after upgrading intellij to 2020.1

情到浓时终转凉″ 提交于 2021-01-29 05:10:25
问题 I just upgraded IntelliJ community edition to latest version 2020.1 as of today. All my SBT run/debug configurations are broken and currently show Unknown under Edit configuration. I have checked the workspace.xml and configuration seems correct. I have also checked I've got the latest SBT plugin. Any help or pointers will be much appreciated as I have dozens of projects with lots of configurations so will be annoying to have to create them again. 回答1: After a couple of hours finally figure

Updating an Environment in Scala

白昼怎懂夜的黑 提交于 2021-01-29 05:00:25
问题 I'm taking some predefined semantic rules and implementing them as an interpreter for the lettuce language using Scala. In Multi-Let, I'm trying to update an environment variable using two lists. I'm sort of new to Scala so I'm not too sure how to do this without converting the environment variable to a List. Is there a way to manipulate the return type in my zip function? I'm getting the following error message. My goal is to get a single updated map rather than a list of updated maps. cmd2

What 's the difference between foldRight and foldLeft in concat

时光总嘲笑我的痴心妄想 提交于 2021-01-29 04:56:38
问题 Why I cannot use fold Left in the following code: def concatList[T](xs: List[T],ys:List[T]): List[T]= (xs foldLeft ys)(_::_) Actually it is hard for me to understand the differences between foldRight and foldLeft, it there any examples to illustrate the real differences? Thanks. 回答1: Well, you can, scala> def concatList[T](xs: List[T],ys:List[T]) = (xs foldLeft ys)( (a, b) => b :: a ) concatList: [T](xs: List[T], ys: List[T])List[T] scala> concatList(List(1,2,3), List(6,7,8)) res0: List[Int]

How to call real method on a stub

送分小仙女□ 提交于 2021-01-29 04:41:47
问题 Is there a way to call a real method on a stubbed object with scalamock? I would like to be able to do something like this: class MySpec extends FunSpec with Matchers with MockFactory { trait MyTrait { def f1: Int def f2: Int = f1 } describe("my feature") { it("should work") { val t = stub[MyTrait] (t.f1 _).when().returns(15) // I would like to do the following: // (t.f2 _).when().callRealMethod() t.f2 should be (15) } } } Note: I was able to work around the issue by making f2 final but I

How to call real method on a stub

旧城冷巷雨未停 提交于 2021-01-29 04:37:33
问题 Is there a way to call a real method on a stubbed object with scalamock? I would like to be able to do something like this: class MySpec extends FunSpec with Matchers with MockFactory { trait MyTrait { def f1: Int def f2: Int = f1 } describe("my feature") { it("should work") { val t = stub[MyTrait] (t.f1 _).when().returns(15) // I would like to do the following: // (t.f2 _).when().callRealMethod() t.f2 should be (15) } } } Note: I was able to work around the issue by making f2 final but I