Scala flatten List

后端 未结 5 1741
無奈伤痛
無奈伤痛 2020-12-29 11:13

I want to write a function that flats a List.

object Flat {
  def flatten[T](list: List[T]): List[T] = list match {
    case Nil => Nil
    case head :: N         


        
5条回答
  •  情深已故
    2020-12-29 11:42

      def flatten(ls: List[Any]): List[Any] = ls flatMap {
        case ms: List[_] => flatten(ms)
        case e => List(e)
      }
    

提交回复
热议问题