Skip to content

Instantly share code, notes, and snippets.

@pelletier
Created August 4, 2010 10:20
Show Gist options
  • Save pelletier/507940 to your computer and use it in GitHub Desktop.
Save pelletier/507940 to your computer and use it in GitHub Desktop.
I know this function already exists, but here is my idea of implementation.
% Converts a tuple to a list.
% {a, b, c, d} -> [a, b, c, d]
tuple_to_list(T) ->
tuple_to_list(T, 0).
tuple_to_list(_T, -1) ->
[];
tuple_to_list(T, Id) ->
Max = tuple_size(T) - 1,
E = if
Id > Max ->
Nid = -1,
[];
true ->
Nid = Id +1,
[element(T, Id)]
end,
lists:append(E, tuple_to_list(T, Nid)).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment