Created
February 15, 2010 14:52
-
-
Save davidcoallier/304696 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%% 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