Skip to content

Instantly share code, notes, and snippets.

@dschinkel
Last active September 16, 2018 02:47
Show Gist options
  • Save dschinkel/e98aac90f4d2b63eed0e7dd1f6c2495c to your computer and use it in GitHub Desktop.
Save dschinkel/e98aac90f4d2b63eed0e7dd1f6c2495c to your computer and use it in GitHub Desktop.
Elm - Helper Functions I've Created
{--
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