Learning Functional Programming in Go
上QQ阅读APP看书,第一时间看更新

Contains

Let's consider another common collection operation: contains.

In Go, lists of things are often stored in a slice. Wouldn't it be nice if Go provided a contains method to tell us whether the item we are looking for is contained in the slice? Since there is no generic contains method for working with lists of items in Go, let's implement one to iterate over a collection of car objects.