Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-15322] Inconsistent behavior of contains in StrideTo/StrideThrough #57644

Open
swift-ci opened this issue Oct 13, 2021 · 0 comments
Open
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. standard library Area: Standard library umbrella

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-15322
Radar None
Original Reporter Ragozin (JIRA User)
Type Bug
Additional Detail from JIRA
Votes 1
Component/s Standard Library
Labels Bug
Assignee None
Priority Medium

md5: f2854433a036457a93fa1ca80d5ff30e

Issue Description:

StrideTo/StrideThrough conform to Sequence protocol and as such implement contains(_: ) and contains(where: ). When the stride is sorted in descending order, these methods return different values, although Sequence itself makes no assumptions about the order of the elements, and neither StrideTo/StrideThrough implementation documents such behavior.

var descStride = stride(from: 4, to: -2, by: -1)

descStride.contains(2) // erroneously returns false

descStride.contains { $0 == 2 } // returns true

descStride.sorted(by: >).contains(2) // returns true

descStride.sorted(by: <).contains(2) // returns true

Compare this to ascending stride behavior:

var ascStride = stride(from: -2, to: 4, by: 1)

ascStride.contains(2) // returns true

ascStride.contains { $0 == 2 } // returns true

ascStride.sorted(by: >).contains(2) // returns true

ascStride.sorted(by: <).contains(2) // returns true
@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. standard library Area: Standard library umbrella
Projects
None yet
Development

No branches or pull requests

1 participant