|
|
| Author |
Message |
< Erlang ~ foldl function call itself |
| mccmike |
Posted: Fri Mar 05, 2010 12:32 am |
|
|
|
Joined: 16 Feb 2010
Posts: 3
|
Stepping thru a large deep list
Within this list are tuples that contain lists.
Is it possible to call the foldl fun from within the foldl fun when I encounter one of these tuples?
Trying to do this
Walk = fun(Rec, Acc) ->
io:format("~nWalking ~p",[Rec])
case is_tuple(Rec) of
true -> lists:foldl(Walk, [], (Rec tuple list)
false -> ok
end
end,
lists:foldl(Walk, [], Doc). |
|
|
| Back to top |
|
| bpuzon |
Posted: Fri Mar 05, 2010 12:55 pm |
|
|
|
User
Joined: 05 Aug 2009
Posts: 23
Location: Cracow, Poland
|
You have to pass the function as the paramenter - like:
Code:
Walk = fun(Rec, {Fun, Acc}) ->
io:format("~nWalking ~p~n",[Rec]),
case is_tuple(Rec) of
true -> {Fun, lists:foldl(Fun, {Fun, Acc}, (Rec tuple list))};
false -> {Fun, ok}
end
end,
lists:foldl(Walk, {Walk, []}, Doc)
|
_________________ Saludos,
Bartłomiej Puzoń
Erlang Solutions |
|
| Back to top |
|
| mccmike |
Posted: Fri Mar 05, 2010 4:02 pm |
|
|
|
Joined: 16 Feb 2010
Posts: 3
|
|
| Back to top |
|
|
|
All times are GMT
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum
|
|
|