Skip to content

Instantly share code, notes, and snippets.

@garazdawi garazdawi/lists.erl
Created Feb 13, 2014

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

commented Feb 13, 2014

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
You can’t perform that action at this time.