[erlang-questions] specs for fixed length lists

Lukas Larsson lukas@REDACTED
Mon Jul 9 22:54:07 CEST 2012


Writing a generic tuple:map/2 would not be that hard either:

map(F, Tuple) ->
   map(F, Tuple, size(Tuple)).

map(F,Tuple,1) ->
   setelement(1,Tuple,F(element(1,Tuple)));
map(F,Tuple,N) ->
   map(F,setelement(N,Tuple,F(element(N,Tuple))),N-1).

It's not very pretty, or efficient, but it gets the job done.

Lukas

On Mon, Jul 9, 2012 at 9:59 PM, Daniel Goertzen
<daniel.goertzen@REDACTED> wrote:
>
> On Sun, Jul 8, 2012 at 1:22 AM, <ok@REDACTED> wrote:
>>
>> I'm with /Joe on this one.  There aren't all _that_ many
>> list operations that make sense on tuples, and
>>     map4(F, {A,B,C,D}) -> {F(A), F(B), F(C), F(D)}.
>> is easy enough to define.  Perhaps the code needs turning
>> inside out.
>>
>
> Thanks for the idea; my functional instincts are still developing.  I will
> go with this approach since my sequence size really is only 4.
>
> Dan.
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>



More information about the erlang-questions mailing list