Generalise the type of filter_map.