Skip to content

Instantly share code, notes, and snippets.

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