Skip to content

Instantly share code, notes, and snippets.

@kyanny
Created January 24, 2011 17:05
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 kyanny/793531 to your computer and use it in GitHub Desktop.
Save kyanny/793531 to your computer and use it in GitHub Desktop.
-module(foreach_with_index).
-export([foreach_with_index/2]).
-export([test/0]).
foreach_with_index(F, L) ->
foreach_with_index(F, L, 1).
foreach_with_index(F, [H|T], I) ->
[F(H, I)|foreach_with_index(F, T, I+1)];
foreach_with_index(_, [], _) -> [].
test() ->
foreach_with_index:foreach_with_index(fun(X, I) -> [I, X*2] end, [3,1,4,1,5,9]).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment