Created
August 4, 2011 15:34
-
-
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
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
| % 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