aboutsummaryrefslogtreecommitdiff
path: root/challenge-326/deadmarshal/erlang/ch2.erl
blob: ece1fb03bb2dd7827c38e7a715e7ac25337877e3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
-module(ch2).
-export([decompressed_list/1]).

-spec pairs(L,L) -> R when 
    L :: [T],
    R :: [T],
    T :: integer().
pairs([],Acc) -> lists:reverse(Acc);
pairs([A,B|T],Acc) -> pairs(T,[{A,B}|Acc]).

-spec decompressed_list(L) -> R when 
    L :: [T],
    R :: [T],
    T :: integer().
decompressed_list(L) ->
  lists:flatmap(fun({A,B}) -> lists:duplicate(A,B) end,pairs(L,[])).