[erlang-questions] How best to extract value from mnesia query
lloyd@REDACTED
lloyd@REDACTED
Wed Nov 15 21:04:24 CET 2017
Hello,
The result of a mnesia read transaction looks like this:
{atomic, Results} where result is either a populated list [value1, ... valueN] or, an empty list [].
If the table is initialized as set, then the returned list will contain at most one value, e.g:
[value].
If I want to use of the value in a function or to populate another record, I need to extract the value from the list.
I've tried various ways to do this, but they all seem clumsy:
E.g.
[MyValue]
hd[vlaue]
confirm([]) ->
not_found;
confirm([Value]) ->
Value;
confirm(Value) ->
Value.
Does there happen to be a preferred/conventional/best-practices way to do this?
Many thanks,
LRP
More information about the erlang-questions
mailing list