我正在使用 Scala 的implicit class
机制,但无法java.lang.String
识别为Iterable[A]
.
implicit class PStream[E](stream: Iterable[E]) {
def splitOn(test: Iterable[E] => Boolean): Option[(Iterable[E], Iterable[E])] = {
???
}
}
仅通过上述定义,IntelliJ 和 SBT 声明......
错误:(31, 8) value splitOn is not a member of String 可能的原因:可能在 `value splitOn' 之前缺少分号?.splitOn(s => Character.isWhitespace(s.head))
...当我尝试这个...
line: String =>
val Some((identifier: String, patternn: String)) =
line
// take the identifier
.splitOn(s => Character.isWhitespace(s.head))