I came across an unexpected implementation of Predef.StringCanBuildFrom , which violates the assumptions I made on CanBuildFrom in my code. Here's the implementation:
implicit def stringCanBuildFrom: CanBuildFrom[String, Char, String] = new CanBuildFrom[String, Char, String] { def apply(from: String) = apply() def apply() = mutable.StringBuilder.newBuilder }
It seems completely unnatural that apply(String) just ignores the parameter. For me, the correct implementation should be
implicit def stringCanBuildFrom: CanBuildFrom[String, Char, String] = new CanBuildFrom[String, Char, String] { def apply(from: String) = apply() ++= from def apply() = mutable.StringBuilder.newBuilder }
but it seems so trivial that I cannot believe that I am one of those who have noticed this, since language exists. I was tempted to open the problem for this, but if I lacked any good reason not to do what I suggested, tell me!
source share