Is it possible to write a faster equivalent to this function?
prepend(X, Tuple) ->
list_to_tuple([X | tuple_to_list(Tuple)]).
Is it possible to write a faster equivalent to this function?
prepend(X, Tuple) ->
list_to_tuple([X | tuple_to_list(Tuple)]).
It looks to me like that sort of thing is discouraged. If you want a list, use one.
Tuples have a fixed number of things in them.
If you have a finite number of possible tuple lengths, you could do this:
prepend(X, {}) -> {X};
prepend(X, {A}) -> {X, A};
prepend(X, {A, B}) -> {X, A, B};
prepend(X, {A, B, C}) -> {X, A, B, C}.
You can continue this pattern for as long as you need.