November 2017
Intermediate to advanced
670 pages
17h 35m
English
Now, let's exercise our Contains() method:
func main() { crv := &Car{"Honda", "CRV"} is250 := &Car{"Lexus", "IS250"} highlander := &Car{"Toyota", "Highlander"} cars := Cars{crv, is250, highlander} if cars.Contains("Highlander") { println("Found Highlander") } if !cars.Contains("Hummer") { println("Did NOT find a Hummer") }}
The output will be as follows:
Found HighlanderDid NOT find a Hummer
In order to understand how to make the leap from imperative programming to functional programming, let's look at pure functional programming languages and how to implement high-order functions such as Map() that manipulate collections.
With pure functional types, you had a function, f, that takes a cube and returns a heart, as shown ...