Skip to content

Instantly share code, notes, and snippets.

@jamhed
Created December 22, 2015 06:32
Show Gist options
  • Save jamhed/3016e43d9fbfecd09571 to your computer and use it in GitHub Desktop.
Save jamhed/3016e43d9fbfecd09571 to your computer and use it in GitHub Desktop.
map_spec_field(state, false) -> '$1';
map_spec_field(_, false) -> '_';
map_spec_field(F, {F, V}) -> V.
make_match_spec(Props) ->
lists:foldl(
fun
(F, Tuple) ->
erlang:append_element(Tuple, map_spec_field(F, lists:keyfind(F, 1, Props)))
end, {game}, record_info(fields, game)).
make_full_match_spec(Props) ->
[{ make_match_spec(Props), [{'=/=','$1',finished}], ['$_'] }].
make_count_match_spec(Props) ->
[{ make_match_spec(Props), [{'=/=','$1',finished}], [true] }].
online() -> online([]).
online(Props) when is_list(Props) ->
Decoded = decode_props(Props),
{atomic, Records} = mnesia:transaction(fun() -> mnesia:select(game, make_full_match_spec(Decoded)) end),
Count = ets:select_count(game, make_count_match_spec(Decoded)),
{Count, Records}.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment