Created
December 6, 2024 08:02
-
-
Save einarwh/d347caff2221be6ca0409ae3a6ebe163 to your computer and use it in GitHub Desktop.
Array2D module.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Array2D = | |
let tryGet (a : 'a[,]) (x, y) = | |
let first = y >= 0 && y < a.GetLength(0) | |
let second = x >= 0 && x < a.GetLength(1) | |
if first && second then Some (Array2D.get a y x) else None | |
let positions (a : 'a[,]) = | |
let rowCount = a.GetLength(0) | |
let colCount = a.GetLength(1) | |
[for x in [0..colCount-1] do for y in [0..rowCount-1] -> (x, y)] | |
let fromList (lst : 'a list list) = | |
let width = lst |> List.head |> List.length | |
let height = lst |> List.length | |
Array2D.init height width (fun y x -> lst |> List.item y |> List.item x) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment