Last active
September 16, 2018 02:47
-
-
Save dschinkel/e98aac90f4d2b63eed0e7dd1f6c2495c to your computer and use it in GitHub Desktop.
Elm - Helper Functions I've Created
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
{-- | |
Overview | |
- this only works with List or Array of Char. I'll change it to be generic soon. | |
- Example list sent in: [['X',' ',' '],['O','O',' '],['X',' ',' ']] : List (List Char) | |
- After Conversion it's type of Array.Array (Array.Array Char) | |
##### If you'd like to try this out in elm repl, run the following:##### | |
import Array | |
import List | |
list = [['X',' ',' '],['O','O',' '],['X',' ',' ']] | |
twoDimensionalListToArray : List (List a) -> Array.Array (Array.Array a) \ | |
twoDimensionalListToArray list = \ | |
let \ | |
node = \ | |
List.map Array.fromList list \ | |
in \ | |
Array.fromList node | |
twoDimensionalArray = twoDimensionalListToArray list | |
--} | |
twoDimensionalListToArray : List (List Char) -> Array.Array (Array.Array Char) | |
twoDimensionalListToArray list = | |
let | |
-- convert child lists to be arrays | |
node = | |
List.map fromList list | |
in | |
-- finally convert outer list to be an array | |
fromList node |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment