# others - scala - 如何将 List[List[Long]] 转换为List[List[Int]]？

``````
val l: List[List[Long]] = List(List(11, 10, 11, 10, 11), List(8, 19, 24, 0, 2))

l.map(_.map(_.toInt))

``````

``````
res2: List[List[Int]] = List(List(11, 10, 11, 10, 11), List(8, 19, 24, 0, 2))

``````

``````
import cats.Functor

import cats.implicits._

import cats.data._

val l: List[List[Long]] = List(List(11, 10, 11, 10, 11), List(8, 19, 24, 0, 2))

Functor[List].compose[List].map(l)(_.toInt)

//or

Nested(l).map(_.toInt).value

``````

``````
val l1: List[List[Long]] = List(List(11, 10, 11, 10, 11), List(8, 19, 24, 0, 2))

val l2: List[List[Int]] = l1.map(list => list.map(long => long.toInt))

``````

`map`通过将函数应用于列表中的每个元素来工作，你需要像下面的示例一样应用map函数2次。

``````
val x : List[List[Long]] = List(List(11, 10, 11, 10, 11), List(8, 19, 24, 0, 2))

println(x)

val y :List[List[Int]]= x.map(a => a.map(_.toInt))

println(y)

``````

``````
List(List(11, 10, 11, 10, 11), List(8, 19, 24, 0, 2))

List(List(11, 10, 11, 10, 11), List(8, 19, 24, 0, 2))

``````