Scala 将列表列表转换为流函数式编程

Scala 将列表列表转换为流函数式编程,scala,functional-programming,recursive-datastructures,Scala,Functional Programming,Recursive Datastructures,我正在使用Scala将列表列表转换为自定义对象“点”列表 在这种情况下,我应该使用Foreach还是应该使用Map或Foreach def list_To_Point(_listOfPoints :List[List[String]]) : List[Point] = { var elem = lazy val _list: List[Point] = _listOfPoints.map(p=> new Point(p[0],p[1]) _list

我正在使用Scala将列表列表转换为自定义对象“点”列表

在这种情况下,我应该使用Foreach还是应该使用Map或Foreach

def list_To_Point(_listOfPoints :List[List[String]]) : List[Point] = { 

    var elem = 
    lazy val _list:  List[Point] = _listOfPoints.map(p=> new Point(p[0],p[1])
      _list
  }   

我不知道问题到底在哪里?

< P>丑如地狱,未经考验,但应该奏效(请考虑让你的结构不变):


<丑陋如地狱,未经考验,但它应该起作用(请考虑让你的结构不变):

但是你真的不应该用列表[String]来表示基本上是
(Int,Int)


但是你真的不应该用列表[String]来表示基本上是
(Int,Int)

为什么不使用元组作为内部结构呢?我不认为我需要它,因为它们都是一样的。我需要知道如何每次在列表中推送一个新的点对象为什么不使用元组作为内部结构?我不认为我需要,因为它们都是尽快的。我需要知道如何每次在列表中推送一个新的点对象
def list_To_Point(_listOfPoints :List[List[String]]) : List[Point] = { 

    var elem = 
    lazy val _list:  List[Point] = _listOfPoints.map(p=> new Point(p[0],p[1])
      _list
  }   
case class Point(x:Int,y:Int) 




object Point {


  def listToPoint(listOfPoints:List[List[String]]):List[Point] =
    listOfPoints.map(p => new Point(p(0).toInt,p(1).toInt))
}
 def listToPoint(l:List[List[String]]):List[Point] = 
     l.collect({case x::y::Nil => new Point(x.toInt,y.toInt)})