Selecting record from list of records by multiple values. How?

Got confused with very simple issue. Got totally forgotten how to select records from list of records by multiple values. For example:

[
    #record{id = <<"jgkjhgkjhg">>, value1 = 1, value2 = "string",value4 = 24}
    #record{id = <<"bvcxdgfss">>, value1 = 1, value2 = "test",value4 = 24}
    #record{id = <<"uytiubjhgs">>, value1 = 2, value2 = "test",value4 = 13}
    #record{id = <<"jvdsewsss">>, value1 = 1, value2 = "string",value4 = 15}
    #record{id = <<"kjffjghjhgfs">>, value1 = 2, value2 = "test",value4 = 67}
]

Need to select all records from list that have value1 = 2 and value2 = “test”.

Solution found https://stackoverflow.com/questions/15073965/erlang-record-handling-using-filter

Got forgotten how to user records in lists:filter/2 with guards

You could also use a list comprehension:
[R || #record{value1 = 1, value2 = "test"} = R <- L]

2 Likes