November 2017
Intermediate to advanced
670 pages
17h 35m
English
A few lines down in our main.go file, let's define a filter function that will return cars whose Make is Honda. We use our new Where method and pass it our honda literal function:
honda := func (c Car) bool { return c.Make == "Honda"}fmt.Println("filter cars by 'Honda':", cars.Where(honda))
Here's the output:
filter cars by 'honda': [{honda accord 3000} {honda accord es 3500}]
Cool. Next, let's create a mapping function to return the price field:
price := func (c Car) Dollars { return c.Price}fmt.Println("Hondas prices:", cars.Where(honda).SelectDollars(price))
Here's the output:
hondas prices: [3000 3500]
Since we have already filtered by Honda, the result only contains the prices of Honda cars.
Aggregation? Sure, ...