-
-
Save sergiosette/9ada0ec0db904627f334ec235566d3c5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public func diff4<T1, T2>(_ first: [T1], _ second: [T2], with compare: (T1,T2) -> Bool) -> SequenceDiff<T1, T2> { | |
let combinations = first.flatMap { firstElement in (firstElement, second.first { secondElement in compare(firstElement, secondElement) }) } | |
let common = combinations.filter { $0.1 != nil }.flatMap { ($0.0, $0.1!) } | |
let removed = combinations.filter { $0.1 == nil }.flatMap { ($0.0) } | |
let inserted = second.filter { secondElement in !common.contains { compare($0.0, secondElement) } } | |
return SequenceDiff(common: common, removed: removed, inserted: inserted) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment