[erlang-questions] An Erlang 101 question

lloyd@REDACTED lloyd@REDACTED
Thu Jul 16 21:02:58 CEST 2015


Hello,

I have several functions that look like this:

get_contact(Email) ->
  open_db(),
  Result = dets:lookup(?contacts, Email),
  close_db(),
  Result.

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?

Thanks,

LRP






More information about the erlang-questions mailing list