Why can't you use lists:foldl(fun(E,Cnt) -> ..., Cnt+1 end, 0, Y). ? Yes, you can:
for_loop_with_index_and_value(F, L) when is_function(F, 2), is_list(L) -> lists:foldl(fun(E, I) -> F(I, E), I+1 end, 0, L).
Overall foldl with index:
foldli(F, L, Acc0) when is_function(F, 3), is_list(L) -> {_, Result} = lists:foldl(fun(E, {I, Acc}) -> {I+1, F(I, E, Acc)} end, {0, Acc0}, L), Result.
map with index:
mapi(F, L) when is_function(F, 2), is_list(L) -> {Result, _} = lists:mapfoldl(fun(E, I) -> {F(I, E), I+1} end, 0, L), Result.