I’m still new to functional programming so if I can’t figure out how to do something I revert back to procedural style. I found a way to get around having to convert to a list but I’d still like to know how.
Here is my attempt to convert a two dimensional array to a list.
let board = Array2.init 10 20 (fun i j -> pull(i, j)) let mutable pieces = [] board |> Array2.mapi (fun i j a -> transform(i, j, a)) |> Array2.iter (fun a -> (pieces <- a :: pieces))
Apparently in .Net, multi-dimensional arrays are IEnumerable (non-generic), and thus this works:
EDIT: As Noldorin points out in a comment, this is even better: