Skip to content

Instantly share code, notes, and snippets.

@thanos
Created August 4, 2011 15:34
Show Gist options
  • Select an option

  • Save thanos/1125457 to your computer and use it in GitHub Desktop.

Select an option

Save thanos/1125457 to your computer and use it in GitHub Desktop.
Couchdb: An erlang map function to get a value from a sub record
% Couchdb: An erlang map function to get a value from a sub record
%
% gets and emits a record for each sub record in legs keyed by "value_date"
% For the date see: https://gist.github.com/1125467
%
fun({Doc}) ->
Bump = fun(Doc, Rec, Field) ->
case {proplists:get_value(Field, Rec)} of
{undefined} ->
ok;
{Key} ->
proplists:expand(Rec, Doc),
Emit(Key, {Rec})
end
end,
Legs = proplists:get_value(<<"legs">>, Doc),
XX = [Bump(Doc, X, <<"value_date">>) || {X} <- Legs]
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment