[erlang-questions] Finding records in List
Thu Jan 13 11:20:28 CET 2011
On Thu, Jan 13, 2011 at 6:06 PM, Arnaud GARCIA <> wrote:
> (still learning erlang ;-)
> I would like to find all records matching criterion/criteria in a list of
> if you have one criteria, you can use:
> => But, it will return just the first one who match the criteria
> =>Moreover with lists:keyfind I didn't find a way for multiple criteria like
> : find all person in list where Name= and Age=
> I saw an interesting post using record<->proplists... is it the way to do it
> Finally, I build my own function which parse the List and check if it match
> the criterion or criteria BUT I was asking if there is an erlang function to
> do this ?
Well, it depends on if you know what these things are at compile time or not.
If you are doing this at compile time, you can simply use a list comprehension:
[P || P <- people(), P#person.name =:= Name, P#person.age =:= Age].
More information about the erlang-questions