Skip to content

Commit c9f4541

Browse files
authored
Create foldr.erl
1 parent 9c1b7f4 commit c9f4541

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

erlang/foldr.erl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
-module(main).
2+
3+
-export([
4+
xs/0,
5+
proc/2,
6+
start/0
7+
]).
8+
9+
xs() -> [{a, 1}, {b, 2}, {c, 3}].
10+
11+
proc({a, Val}, State) -> State + Val;
12+
proc({b, Val}, State) -> State - Val;
13+
proc({c, _}, State) -> State;
14+
proc(_, State) -> State.
15+
16+
start() ->
17+
Fun = fun(Cur, Acc) -> proc(Cur, Acc) end,
18+
XS = lists:foldl(Fun, 0, xs()),
19+
io:fwrite("~p~n", [ XS ]).

0 commit comments

Comments
 (0)