simpler impl of preserving type when filtering