Skip to content

Array<T: ContentEquatable> does not conform to ContentEquatable #100

Closed
@nkristek

Description

@nkristek

Checklist

Description

Similar to the conditional Equatable conformance Array<T: ContentEquatable> should also conditionally conform to ContentEquatable.

Motivation and Context

This potentially simplifies the implementation of ContentEquatable and thus Differentiable of a container type, if it contains an array of equatable/differentiable items.

Proposed Solution

extension Array: ContentEquatable where Element: ContentEquatable {
    @inlinable
    public func isContentEqual(to source: Array<Element>) -> Bool {
        return count == source.count
            && zip(self, source).allSatisfy { $0.isContentEqual(to: $1) }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions