-
-
Save laevandus/d468955eb75a995c8a0fd285ede10f7a 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
struct Item: Identifiable { | |
let id: String | |
let date: Date | |
} | |
let referenceDate = Date(timeIntervalSince1970: 1711282131) | |
let original: [Item] = [ | |
Item(id: "1", date: referenceDate.addingTimeInterval(1.0)), | |
Item(id: "2", date: referenceDate.addingTimeInterval(2.0)), | |
Item(id: "3", date: referenceDate.addingTimeInterval(3.0)), | |
Item(id: "4", date: referenceDate.addingTimeInterval(4.0)), | |
Item(id: "5", date: referenceDate.addingTimeInterval(5.0)), | |
] | |
let other: [Item] = [ | |
Item(id: "3", date: referenceDate.addingTimeInterval(1.5)), | |
Item(id: "7", date: referenceDate.addingTimeInterval(2.5)), | |
Item(id: "4", date: referenceDate.addingTimeInterval(4.0)), | |
Item(id: "5", date: referenceDate.addingTimeInterval(5.5)), | |
Item(id: "6", date: referenceDate.addingTimeInterval(8.0)), | |
] | |
let result = original.sortedMerged(with: other, areInIncreasingOrder: { $0.date < $1.date }) | |
result.forEach { item in | |
print("\(item.id) - \(item.date.timeIntervalSince(referenceDate))") | |
} | |
// 1 - 1.0 | |
// 3 - 1.5 | |
// 2 - 2.0 | |
// 7 - 2.5 | |
// 4 - 4.0 | |
// 5 - 5.5 | |
// 6 - 8.0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment