
上QQ阅读APP看书,第一时间看更新
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.