Skip to content

Instantly share code, notes, and snippets.

@garazdawi
Created February 13, 2014 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save garazdawi/8975779 to your computer and use it in GitHub Desktop.
Save garazdawi/8975779 to your computer and use it in GitHub Desktop.
nmap(F,List) ->
nmap(F,erlang:fun_info(F,arity),List).
nmap(F,Ar,List) ->
{Hd,Tl} = lists:split(Ar,List),
[apply(F,Hd)|nmap(Tl)];
nmap(_F,_,[]) ->
[].
@psyeugenic
Copy link

I rewrote it =)

%% usage:
%% mmap(fun(A,B) -> [{A,B}] end, [1,2,3,4]),
%% [{1,2},{3,4}]

mmap(F,List) -> 
    {arity,Ar} = erlang:fun_info(F,arity),
    mmap(F,Ar,List).
mmap(_F,_,[]) -> [];               
mmap(F,Ar,List) ->
    {Hd,Tl} = lists:split(Ar,List),
    apply(F,Hd) ++ mmap(F,Ar,Tl).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment