17

How can I write map-reduce functions in Erlang for CouchDB? I am sure Erlang is faster than JavaScript.

Jim Puls
  • 79,175
  • 10
  • 73
  • 78
edbond
  • 3,921
  • 19
  • 26

2 Answers2

25
pmap(F, L) ->
    Parent = self(),
    Pids = [spawn(fun() ->
                     Parent ! {self(), F(X)}
                  end) || X -> L],
    [receive {Pid, Res} -> Res end || Pid < - Pids].

I believe I did, Bob.

Fu.
  • 446
  • 4
  • 10
16

You can do so using erlview, which is within the top ten hits on Google for "couchdb erlang view" and is listed on the CouchDB wiki page for other-language view servers.

Jim Puls
  • 79,175
  • 10
  • 73
  • 78
  • With the next release of CouchDB erlang views will be built in. You won't even have to download and setup erlview to make it work. – Jeremy Wall Aug 21 '09 at 03:38
  • 2
    CouchDB 0.10 (released October 2009) and later support Erlang views natively. A good writeup is at http://blog.echolibre.com/2010/02/couchdb-custom-erlang-map-functions/ – JasonSmith Jun 12 '10 at 07:51