Skip to content

Instantly share code, notes, and snippets.

@ngnguyen1
Created June 20, 2016 18:21
Show Gist options
  • Save ngnguyen1/05effddbb324d9fa5fdee2cfad8860c2 to your computer and use it in GitHub Desktop.
Save ngnguyen1/05effddbb324d9fa5fdee2cfad8860c2 to your computer and use it in GitHub Desktop.
%% fold here
fold(_, Start, []) -> Start;
fold(F, Start, [H|T]) -> fold(F, F(H,Start), T).
%% Use fold to write the map function.
map(F,L) -> fold(fun(X, Acc) -> [F(X)|Acc] end, [], L).
%% Exp: map(fun(X) -> X+1 end, lists:seq(1,3)). => [2,3,4]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment