The where Clause

If you wanted to provide an extra utility knife for the List collection, you could write a couple functions that do some useful stuff to the List. You will have very strict criteria for the parameters of the function, even more strict than a protocol. Enter the where clause! You can specify that parameters must meet certain criteria before being passed in. This of it like a bouncer at a club. Let’s say you were comparing two Lists—you would want to make sure that both Lists being passed in meet the criteria of a List. You could make a function that will combine all Lists passed in and deDup them all at once, leaving you with one list with all unique values:

protocol Bucket {    typealias SomeItem ...

Get Learning Swift™ Programming now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.