Skip to content

Instantly share code, notes, and snippets.

@fenollp
Last active August 29, 2015 14:00
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 fenollp/11190937 to your computer and use it in GitHub Desktop.
Save fenollp/11190937 to your computer and use it in GitHub Desktop.
-module(propfolding).
-export([get/1]).
get (Doc) ->
{Stars, AreaID, CheckinDate, HotelID, Rooms} =
lists:foldl(
fun
({<<"stars">>, Stars}, Acc) -> setelement(1, Acc, Stars);
({<<"areaID">>, AreaID}, Acc) -> setelement(2, Acc, AreaID);
({<<"checkinDate">>, <<Year:4, $-, Month:2, $-, Day:2>>}, Acc) ->
setelement(3, Acc, binary_to_integer(<<Year/binary, Month/binary, Day/binary>>));
({<<"hotelID">>, HotelID}, Acc) -> setelement(4, Acc, HotelID);
({<<"rooms">>, Rooms}, Acc) -> setelement(5, Acc, Rooms)
end,
erlang:make_tuple(5, undefined),
Doc),
%% blablabla
ok.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment