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 List
s—you would want to make sure that both List
s being passed in meet the criteria of a List
. You could make a function that will combine all List
s 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 the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.