scala-2.11

pattern match returns a different result for ArrayBuffer and Seq

感情迁移 提交于 2019-12-12 19:04:30
问题 In the sample below, there is a function seqResult that pattern matches against a Seq . Another function that accepts variable arguments calls seqResult and passes in an ArrayBuffer . This causes the pattern match result to be different when called with a Seq or with an ArrayBuffer . With a Seq the matcher hits case head :: rest => ... , with an ArrayBuffer the matcher hits case Seq(one, two) => ... . Is this a bug? Is there anyway to safeguard against this? If it's not a bug, what is a safe

Conflicting cross-version suffixes in: org.scalamacros:quasiquotes

有些话、适合烂在心里 提交于 2019-12-12 14:24:48
问题 I am trying to use scala-pickling in one of my projects. I tried to mimic the build file of macroid which seems to use pickling too but I keep getting this error on sbt test : [error] Modules were resolved with conflicting cross-version suffixes in dijon: [error] org.scalamacros:quasiquotes _2.10, _2.10.3 java.lang.RuntimeException: Conflicting cross-version suffixes in: org.scalamacros:quasiquotes at scala.sys.package$.error(package.scala:27) at sbt.ConflictWarning$.processCrossVersioned

Scala String Interpolation with Underscore

夙愿已清 提交于 2019-12-11 04:25:43
问题 I am new to Scala so feel free to point me in the direction of documentation but I was not able to find an answer to this question in my research. I am using scala 2.11.8 with Spark2.2 and trying to create a dynamic string containing dateString1_dateString2 (with underscores) using interpolation but having some issues. val startDt = "20180405" val endDt = "20180505" This seems to work: s"$startDt$endDt" res62: String = 2018040520180505 But this fails: s"$startDt_$endDt" <console>:27: error:

Scalaz unboxed tagged type not automatically unboxed

不羁的心 提交于 2019-12-10 16:53:29
问题 Reading http://eed3si9n.com/learning-scalaz/Tagged+type.html and trying out the sample code: import scalaz._; import Scalaz._ sealed trait KiloGram def KiloGram[A](a: A): A @@ KiloGram = Tag[A, KiloGram](a) val mass = KiloGram(20.0) 2 * mass according to the guide, should yield 40.0 , however, on Scala 2.11.2 I get: scala> 2 * mass <console>:17: error: overloaded method value * with alternatives: (x: Double)Double <and> (x: Float)Float <and> (x: Long)Long <and> (x: Int)Int <and> (x: Char)Int

Scalac hanging on phase typer of RegexParser

假如想象 提交于 2019-12-10 11:25:30
问题 I have a scala program which among other things has a parser-combinator. This is done by extending scala.util.parsing.combinator.RegexParsers . I had developed it using Scala 2.10 and all was working fine. Yesterday I upgraded my system to Scala 2.11.4, together with IntelliJ 14.02 (not that it matters). However, whenever I try to compile this program now, scalac hangs during this phase: scalac: phase typer on MyParser.scala I changed absolutely nothing to this code, I can't understand why it

Add custom compile time checks to Scala

五迷三道 提交于 2019-12-10 10:44:06
问题 Suppose I have the following Scala code: sealed trait Foo sealed trait Bar object Foo1 extends Foo object Foo2 extends Foo object Foo3 extends Foo object Bar1 extends Bar object Bar2 extends Bar object Bar3 extends Bar case class Hello(foo:Foo, bar:Bar) val a = Hello(Foo1, Bar2) // allowed val b = Hello(Foo2, Bar2) // suppose not allowed I need to catch at compile time if any incompatible combination is applied to Hello . Suppose only the following combinations are allowed: (Foo1, Bar1) ,

canEqual() in the scala.Equals trait

送分小仙女□ 提交于 2019-12-06 18:41:04
问题 From the source code scala/Equals.scala (here): package scala trait Equals extends scala.Any { def canEqual(that: scala.Any): scala.Boolean def equals(that: scala.Any): scala.Boolean } In the documentation, it says: A method that should be called from every well-designed equals method that is open to be overridden in a subclass. I randomly picked a class which extends scala.Equals and which is simple enough to understand. I picked scala.Tuple2[+T1, +T2] , which extends the trait scala.Product

Custom Slick Code Generator 3.0.0

自闭症网瘾萝莉.ら 提交于 2019-12-06 09:49:30
问题 Can slick codegen generate all the mapped case classes outside of the ${container} trait , so that they don't inherit its type? Maybe in another file altogether i.e. Models.scala ? // SuppliersRowsDAA.scala import persistence.Tables object SuppliersRowsDAA { case class Save(sup: Tables.SuppliersRow) } I get this compilation error: [error] /app/src/main/scala/persistence/dal/SuppliersDAA.scala:5: type mismatch; [error] found : persistence.Tables.SuppliersRow [error] required: SuppliersDAA.this

Scalac hanging on phase typer of RegexParser

ε祈祈猫儿з 提交于 2019-12-06 08:51:40
I have a scala program which among other things has a parser-combinator. This is done by extending scala.util.parsing.combinator.RegexParsers . I had developed it using Scala 2.10 and all was working fine. Yesterday I upgraded my system to Scala 2.11.4, together with IntelliJ 14.02 (not that it matters). However, whenever I try to compile this program now, scalac hangs during this phase: scalac: phase typer on MyParser.scala I changed absolutely nothing to this code, I can't understand why it is hanging or from where I should start. IntelliJ had a warning about postfix operators for parser

scala pattern match a function - how to get around type erasure

核能气质少年 提交于 2019-12-06 06:18:46
问题 I would like to pattern match a function, the problem is type erasure. Notice how in the snippet below, despite the warning issued a match occurs and a "wrong" one at that. scala> def f1 = ()=>true f1: () => Boolean scala> val fl = f1 fl: () => Boolean = <function0> scala> scala> fl match { | case fp :Function0[Boolean] => 1 | case _ => 2 | } res8: Int = 1 scala> scala> fl match { | case fp :Function0[String] => 1 | case _ => 2 | } <console>:11: warning: fruitless type test: a value of type (