
上QQ阅读APP看书,第一时间看更新
Filter function
The Filter function is a HOF that takes another HOF, namely ByMake, and performs a data transformation.
func (cars Collection) Filter(fn FilterFunc) Collection {
filteredCars := make(Collection, 0)
for _, car := range cars {
if fn(car) {
filteredCars = append(filteredCars, car)
}
}
return filteredCars
}