Skip to content
bosky101 edited this page Sep 13, 2010 · 2 revisions

Usage
test()→
Eg1Input = [a,b,c,d,a],
Eg1MapFn = fun(a)→{a,"apple"};(b)→{b,"ball"};©→{c,"cat"};(d)→{d,"dog"};(e)→{e,"emul"};(Else)→“unexpected” end ,
Eg1ReduceFn = fun({_K,V})→ lists:foldl( fun(
Char,Ctr)→ Ctr+1 end , 0, V) end,

%% count occurances of a set of words Eg1 = ?MODULE:reduce( ?MODULE:intermediate ( ?MODULE:map(Eg1Input , Eg1MapFn)) , Eg1ReduceFn), Eg2Input = [

{slot1,"11"},
{slot1,"1111"},
{slot2,"2"},
{slot3,"3"},
{slot3,"333"},
{slot3,"2"},
{slot2,"22"},
{slot1,"11"}
],
Eg2MapFn = fun({Slot,X})→
case string:to_integer(X) of
{error,}→
0;
{Numb,_}→
{Slot,Numb}
end
end,
Eg2ReduceFn = fun({
K,V})→ lists:foldl( fun(X,Max) when Max=:= -1 → X;(X,Max)→
case Max > X of
true→ Max;
_ → X
end
end , -1, V) end,

%% find max in different slots Eg2 = ?MODULE:reduce( ?MODULE:intermediate ( ?MODULE:map(Eg2Input , Eg2MapFn)) , Eg2ReduceFn), [ Eg1, %%[{a,2},{b,1},{c,1},{d,1}] Eg2 %%[{slot1,1111},{slot2,22},{slot3,333}] ].
Clone this wiki locally