【发布时间】:2018-11-08 10:46:00
【问题描述】:
如果我想转换一个列表 [[[0; 5]; [1; 5]; [2; 3]]] 到一个元组列表 [(0, 5); (1, 5); (2, 3)] 在 f# 中使用 f# 或模式匹配,请问我该怎么做?
【问题讨论】:
-
你为什么要删除你的中间问题?
标签: f# f#-interactive f#-data c#-to-f# f#-3.0
如果我想转换一个列表 [[[0; 5]; [1; 5]; [2; 3]]] 到一个元组列表 [(0, 5); (1, 5); (2, 3)] 在 f# 中使用 f# 或模式匹配,请问我该怎么做?
【问题讨论】:
标签: f# f#-interactive f#-data c#-to-f# f#-3.0
我会展平列表的外层(通过连接二级列表),然后使用 map 将内层列表转换为元组:
let transform lst =
lst
|> List.concat
|> List.map (function
| [a; b] -> (a, b)
| _ -> failwith "Incorrect list syntax")
【讨论】: