0

I have a list List = [ins_appServer_APP02@mdiaz,ins_appServer_APP04@mdiaz].

and I have an atom that comes as a parameter: AppServerAtom = ins_appServerAPP02@mdiaz

I need help to search in List the element that match with AppServerAtom

It is possible to do this with Erlang?

A. Sarid
  • 3,916
  • 2
  • 31
  • 56
md-86
  • 83
  • 9

2 Answers2

3

Use lists:member/2:

List = ['ins_appServer_APP02@mdiaz', 'ins_appServer_APP04@mdiaz'],
case lists:member('ins_appServer_APP02@mdiaz', List) of
  true -> do_something_when_true();
  false -> do_something_when_false()
end.

See http://erldocs.com/current/stdlib/lists.html?i=0&search=lists:mem#member/2 in the Erlang function reference.

nu-ex
  • 691
  • 4
  • 9
0

If you want get the matched element, you can use lists:filter

lists:filter(fun(X) -> X == AppServerAtom end, List).

If you just want check the element is in the List, you can use lists:member

BlackMamba
  • 10,054
  • 7
  • 44
  • 67