标签: ios generics swift
我想获得c = a\b,其中
c = a\b
let a: [S] let b: [S]
答案 0 :(得分:2)
func diff<S: Equatable>(a: [S], b: [S]) -> [S] { return a.filter { !contains(b, $0) } } diff([1,2,3], [2]) // [1, 3] diff(["foo", "baz", "bar"], ["foo", "bar"]) // ["baz"]