[erlang-questions] list comprehensions speed

Oleg lego12239@REDACTED
Tue Feb 25 14:08:52 CET 2014


  Hello.

I'm erlang newbie. Don't beat me, please :-), if this question is obvious.

I have a list of key-value pairs:

A=[{"name1", 1}, {"name2", 77}, {"name3", 33}, {"name4", 234}].

What is faster:

[ Value || {Name, Value} <- A, string:equal(Name, "name3")].

Or:

get_value(Key, []) ->
  [].
get_value(Key, [H|T]) ->
  {Name, Value} = H,
  case string:equal(Name, Key) of
    true ->
      [Value];
    false ->
      get_value(Key, T)
  end.

start() ->
  get_value("name3", A).



More information about the erlang-questions mailing list