Skip to content

Instantly share code, notes, and snippets.

@TheSeamau5
Last active August 29, 2015 14:12
Show Gist options
  • Save TheSeamau5/31598cf5535387c3a57a to your computer and use it in GitHub Desktop.
Save TheSeamau5/31598cf5535387c3a57a to your computer and use it in GitHub Desktop.
Function to map a function over a grid while passing in the indices
gridMapWithIndices : (Int -> Int -> a -> b) -> List (List a) -> List (List b)
gridMapWithIndices function grid =
let iterateColumns x y columnCount row =
if (x >= columnCount || row == []) then []
else
function x y (head row) :: iterateColumns (x + 1) y columnCount (tail row)
iterateRows y rowCount grd =
if (y >= rowCount) then []
else
iterateColumns 0 y (length <| head grd) (head grd) :: iterateRows (y + 1) rowCount (tail grd)
in iterateRows 0 (length grid) grid
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment