Complete the code to declare a generic function that accepts any type conforming to the Comparable protocol.
func findMax<T: [1]>(_ a: T, _ b: T) -> T { return a > b ? a : b }
The generic type T must conform to Comparable to use the > operator.
Complete the code to constrain the generic type to the Hashable protocol.
func checkAndHash<T: [1]>(_ value: T) -> Int { return value.hashValue }
Equatable instead of Hashable, as Equatable lacks hashValue.Codable or Comparable which do not provide hashValue.The generic type T must conform to Hashable to use hashValue. Hashable inherits from Equatable.
Fix the error in the generic function declaration by filling the correct protocol conformance.
func compareItems<T: [1]>(_ first: T, _ second: T) -> Bool { return first == second }
The equality operator == requires the type to conform to Equatable.
Fill both blanks to declare a generic function where T conforms to Codable and U conforms to Hashable.
func processItems<T: [1], U: [2]>(item1: T, item2: U) { print(item1) print(item2.hashValue) }
The first generic type T conforms to Codable, and the second generic type U must conform to Hashable to access hashValue.
Fill all three blanks to create a generic function where T conforms to Comparable, U conforms to Equatable, and V conforms to Codable.
func genericFunction<T: [1], U: [2], V: [3]>(a: T, b: U, c: V) { if a > a { print(b == b) } print(c) }
The generic type T must conform to Comparable to use >. U must conform to Equatable to use ==. V conforms to Codable.