- Learning Functional Programming in Go
- Lex Sheehan
- 73字
- 2021-07-02 23:13:42
More cars
It's time to add more cars:
moreCars := LoadMoreCars()
PrintCars("More Cars, Domestic, Numeric, GM",
cars.AddCars(moreCars).
Filter(ByDomestic()).
Filter(ByHasNumber()).
Filter(ByMake("GM")))
The output of this is as follows:
More Cars, Domestic, Numeric, GM
-----------------------
car: GM Hummer H2
car: GM Hummer H3
car: GM Oldsmobile Delta 88
car: GM Oldsmobile 442
Wait, what? AddCars? How is that an HOF? AddCars neither takes a function nor returns a function. Even worse, it mutates the cars collection.