Dictionaries: Select where statement

I have some dictionary (based on this introduction), say

test{'Key 1':111, 'Key 2':12, 'Key 3':12, 'Key 4':72, 'Key 5':55}

My aim now is to create some (sub)dictionary, where all Values have some property X (e.g. value is greater than 33). Say I want to build some function in which I can make some select where statement. In the tutorial above I only found select statements.

The typical route for operations that filter/map/… a whole dict is to use dict_pairs/3, use the well known list operations and then again dict_pairs/3 to create a new dict. This is also the efficient route as dict modifications are all O(n) where n is the number of keys. Although the constant factor is low (often just copying an array), many modifications to a dict step-by-step create a lot of garbage dicts that (often) need to be garbage collected some day.

1 Like