Skip to content

Equatable vs EncodableRecord for removeDuplicates() #1143

Answered by groue
oddanderson asked this question in Q&A
Discussion options

You must be logged in to vote

Should I expect to implement Equatable whenever I want to use removeDuplicates()?

In order to compare values that do not conform to Equatable, you have removeDuplicates(by:). You can call databaseEquals there:

ValueObservation
    .tracking { db in try Player.fetchOne(db, id: 42) }
    .removeDuplicate { prev, current in
        switch (prev, current) {
        case (nil, nil):
            return true
        case (let prev?, let current?):
            return prev.databaseEquals(current)
        default:
            return false
        }
    }

Replies: 2 comments 8 replies

Comment options

You must be logged in to vote
7 replies
@oddanderson
Comment options

@groue
Comment options

@groue
Comment options

@oddanderson
Comment options

@groue
Comment options

Answer selected by oddanderson
Comment options

You must be logged in to vote
1 reply
@groue
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants