Does Scala.collection.immutable.WrappedString need an implicit CanBuildFrom to perform documented functions?

WrappedString Scaladoc 2.8.1:

"This class serves as a wrapper to complement the rows with all the operations found in indexed sequences. The difference between this class and StringOps is that transformer method calls, such as a filter and a map , will create an object of type WrappedString , not a string

scala> import scala.collection.immutable.WrappedString import scala.collection.immutable.WrappedString scala> val s = new WrappedString("foo") s: scala.collection.immutable.WrappedString = WrappedString(f, o, o) scala> s.filter(x => true) res1: scala.collection.immutable.WrappedString = WrappedString(f, o, o) scala> s.map(x => x) res2: scala.collection.immutable.IndexedSeq[Char] = Vector(f, o, o) 

Alas, the map returns a vector, not a WrappedString. If I understand this correctly:

The filter works because it just uses the newBuilder method, but the map requires an implicit CanBuildFrom for the WrappedString, like BitSet. Is this a bug in the code or documentation, or am I missing something?

Also, the simplified version of scaladoc doesn't make any sense to me:

 def map [B] (f: (Char) ⇒ B) : WrappedString[B] def map [B, That] (f: (Char) ⇒ B)(implicit bf: CanBuildFrom[WrappedString, B, That]) : That 

Must not be:

 def map [B] (f: (Char) ⇒ Char) : WrappedString def map [B, That] (f: (Char) ⇒ B)(implicit bf: CanBuildFrom[WrappedString, B, That]) : That 

?

+4
source share
1 answer

The first will be a bug that will be fixed for 2.9.

+1
source

Source: https://habr.com/ru/post/1339055/


All Articles