创建 Scala 列表的子列表
Create sublists of scala list
输入:列表(1,2,3)
预期输出 1:
列表(1), 列表(1, 2), 列表(1,2,3)
预期输出 2:
列表(1, 1, 2, 1, 2, 3)
预期输出 1
val l = List(1,2,3)
l.map( x => (l.head to x).toList)
预期输出 2
l.flatMap{ x =>
l.head to x
}
输入:列表(1,2,3)
预期输出 1: 列表(1), 列表(1, 2), 列表(1,2,3)
预期输出 2: 列表(1, 1, 2, 1, 2, 3)
预期输出 1
val l = List(1,2,3)
l.map( x => (l.head to x).toList)
预期输出 2
l.flatMap{ x =>
l.head to x
}