Last active
August 29, 2015 14:12
-
-
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
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
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