F# convert Array2 into a list

和自甴很熟 提交于 2019-12-05 14:42:49
Brian

Apparently in .Net, multi-dimensional arrays are IEnumerable (non-generic), and thus this works:

let a2 = Array2.init 2 3 (fun x y -> (x+1)*(y+1))
let l = a2 |> Seq.cast<int> |> Seq.fold (fun l n -> n :: l) []
printfn "%A" l

EDIT: As Noldorin points out in a comment, this is even better:

let l = a2 |> Seq.cast<int> |> Seq.toList
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!