[erlang-questions] An Erlang 101 question
Thu Jul 16 22:16:11 CEST 2015
This depends a bit in what you're trying to achieve. Do you need a valid
result? Or would some kind of default value be sufficient? In the later
case, you could then also provide a get_contact(Email, Default) that
returns the default value if none was found in the db.
If you require a valid result to appear in your db, then it could still
depend on the rest of your app. Is that something normal you need to be
able to react on? If yes, well, then you need to code for it. If not, then
you might want to consider it an "exceptional" occurrence and simply crash
the process and let the supervisor clean things up.
On Jul 16, 2015 9:03 PM, <lloyd@REDACTED> wrote:
> I have several functions that look like this:
> get_contact(Email) ->
> Result = dets:lookup(?contacts, Email),
> The implication is that the function returns and empty list, , if it
> fails to find a record, otherwise it returns a list containing the record.
> This makes it easy to distinguish the failure-to-return a record
> condition, but means that every function that depends up on get_contact/1
> needs to do so and know what to do in that case. But that begins to feel
> like defensive programming.
> I can see several ways of dealing with this problem, but it occurs to me
> that there must be a conventional approach. What might be... what?
> erlang-questions mailing list
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the erlang-questions