- Learning Functional Programming in Go
- Lex Sheehan
- 53字
- 2025-02-27 05:14:35
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
}