Scala 不再支持List.make,报错"value make is not a member of object List"
Scala no longer supports List.make, error "value make is not a member of object List"
通过示例时
http://aperiodic.net/phil/scala/s-99/p15.scala
// P15 (**) Duplicate the elements of a list a given number of times.
// Example:
// scala> duplicateN(3, List('a, 'b, 'c, 'c, 'd))
// res0: List[Symbol] = List('a, 'a, 'a, 'b, 'b, 'b, 'c, 'c, 'c, 'c, 'c, 'c, 'd, 'd, 'd)
object P15 {
def duplicateN[A](n: Int, ls: List[A]): List[A] =
ls flatMap { List.make(n, _) }
}
行
ls flatMap { List.make(n, _) }
产生编译器错误
"value make is not a member of object List"
还有其他方法可以重写吗?
make
在 2.8.0
中弃用并在 2.11.x
中删除。
您可以使用
ls flatMap { List.fill(n)(_) }
通过示例时 http://aperiodic.net/phil/scala/s-99/p15.scala
// P15 (**) Duplicate the elements of a list a given number of times.
// Example:
// scala> duplicateN(3, List('a, 'b, 'c, 'c, 'd))
// res0: List[Symbol] = List('a, 'a, 'a, 'b, 'b, 'b, 'c, 'c, 'c, 'c, 'c, 'c, 'd, 'd, 'd)
object P15 {
def duplicateN[A](n: Int, ls: List[A]): List[A] =
ls flatMap { List.make(n, _) }
}
行
ls flatMap { List.make(n, _) }
产生编译器错误
"value make is not a member of object List"
还有其他方法可以重写吗?
make
在 2.8.0
中弃用并在 2.11.x
中删除。
您可以使用
ls flatMap { List.fill(n)(_) }