Skip to content

Instantly share code, notes, and snippets.

@Lanayx
Last active July 1, 2018 12:05
Show Gist options
  • Save Lanayx/43265b03e5cf5aa31baaca3a1126def9 to your computer and use it in GitHub Desktop.
Save Lanayx/43265b03e5cf5aa31baaca3a1126def9 to your computer and use it in GitHub Desktop.
Array flattener
type MyElement =
| MyNumber of int
| MyArray of MyElement list
let rec flatten = function
| [] -> []
| (MyNumber head) :: tail -> head :: flatten tail
| (MyArray head) :: tail -> List.append (flatten head) (flatten tail)
[<EntryPoint>]
let main argv =
[ MyArray [ MyNumber 1; MyNumber 2; MyArray [ MyNumber 3 ] ]; MyNumber 4 ]
|> flatten
|> printfn "%A"
0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment