score:4
Accepted answer
This appears to be a bug in the library. Do you want to file the bug or shall I?
scala> Seq.empty match {case Seq() => "yup"; case _ => "nope"}
res0: java.lang.String = yup
scala> Seq() match {case Seq.empty => "yup"; case _ => "nope"}
res1: java.lang.String = yup
scala> ("" : Seq[Char]) match {case Seq() => "yup"; case _ => "nope"}
res2: java.lang.String = yup
scala> ("" : Seq[Char]) match {case Seq.empty => "yup"; case _ => "nope"}
res3: java.lang.String = nope
score:0
In matching the unapply or unapplySeq functions are used, not apply as you seem to believe.
Source: stackoverflow.com
Related Query
- Why does the empty string not match as Seq.empty?
- Why the scala :_* to expand a Seq into variable-length argument list does not work in this case?
- Why does a match on covariant enum does not behave the same as with a sealed trait?
- Why does $ not work with values of type String (and only with the string literals directly)?
- Why does "split" on an empty string return a non-empty array?
- Why to use empty parentheses in Scala if we can just use no parentheses to define a function which does not need any arguments?
- Why does `Array(0,1,2) == Array(0,1,2)` not return the expected result?
- Why does the andThen of Future not chain the result?
- Why does Option not extend the Iterable trait directly?
- Why does Haskell's foldr NOT stackoverflow while the same Scala implementation does?
- Why does this Scala function compile when the argument does not conform to the type constraint?
- Why does auxiliary constructor not see import done in the class?
- Why does Scala warn about type erasure in the first case but not the second?
- Why does scalac not believe that a method does not fit the required type signature?
- Why does @RequestMapping annotation accept String parameter in java but not in scala?
- Why does Scala maintain the type of collection not return Iterable (as in .Net)?
- Why does the Scala compiler say that copy is not a member of my case class?
- Why does chaining match expressions does not compile?
- Why does the compiler not look in the enclosing class for a method?
- scala - why map.size return 0 when the map is not empty
- Scala with spark - "javax.servlet.ServletRegistration"'s signer information does not match signer information of other classes in the same package
- why does scala not match implicitly on tuples?
- Why does my println in rdd prints the string of elements?
- Why does the same scala code work OK in command line while not in Intellij?
- Why does Scala not infer the type parameters when pattern matching with @
- Why this simple Scala for comprehension does not execute the futures?
- Why is the return type of the fold operation Serializable and not String
- Why does the gradle commandline do not show specs2 results?
- Why does scalac not optimize away the overhead in simple `for` constructs?
- Why BsonObjectId::apply(String) method does not work for the second time?
More Query from same tag
- Can akka HttpHeader store an X-Request-ID or X-Correlation-ID Field?
- How to use structural types in isInstanceOf calls?
- Reduce a json string column into a key/val column
- Getting Null Pointer exception in spark UDF
- Slick 2.0 - update two or more columns
- spark read schema types to create insert statement
- Can one impose a coverage minimum for combined unit and integration tests?
- Akka testing supervisor error handling
- Scala:Implicit converters & infix notation & operator precedence
- Scala: "class needs to be abstract, since method is not defined" error
- Scala actors and workers
- Create a SparseVector from the elements of RDD
- Scala Implicit function within a function call
- Scala, Play Framework - "JsUndefined("VALUE1" is not an object)" - is there a better way to deserialise json into Map[String, String]?
- How to use the akka-http cachedHostConnectionPool inside an akka actor?
- Split strings with separator splited into each characters in Scala
- Start external console application from Scala in interactive mode
- Should we use packages like Java style on Scala?
- Type parameter issue in Scala with generic function
- Is it possible to make non-capturing groups work in scala regexes when pattern matching
- How to run and compile exact one test in sbt?
- Getting body bytes from HttpResponse in Netty client
- Scala case class fields
- Downloading Image file using scala
- Scala — negation of a predicate
- How dynamically handle self-type annotation in scala
- Why a Trait extending Abstract Class with non-empty constructor compiles?
- Create an Axios post to send an uploaded file using Dropzone for a Scala function to handle the respective request
- How to create a polymorphic numeric value from a String
- How to pop and return the top element of a stack in scala