Skip to content

Instantly share code, notes, and snippets.

@davidcoallier
Created February 15, 2010 14:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidcoallier/304696 to your computer and use it in GitHub Desktop.
Save davidcoallier/304696 to your computer and use it in GitHub Desktop.
%% Map Function
%%
%% This map function will output the doc.name as the key
%% and the doc.value as the value of that key.
%%
%% In javascript the code would look like:
%%
%% function(doc) {
%% if (doc.name && doc.value) {
%% emit(doc.name, doc.value);
%% }
%% }
fun({Doc}) ->
Emitter = fun(Doc) ->
Name = proplists:get_value(<<"name">>, Doc, null),
Value = proplists:get_value(<<"value">>, Doc),
Emit(Name, Value)
end,
HasRequiredFields = fun(Doc) ->
case {proplists:is_defined(<<"name">>, Doc), proplists:is_defined(<<"value">>, Doc)} of
{true, true} ->
%% In the second post we are going to introduce some integer validation here.
Emitter(Doc);
_->
false
end
end,
HasRequiredFields(Doc)
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment