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-13816] FlattenSequence should conform to LazySequenceProtocol when Base does #56213

Open
swift-ci opened this issue Nov 3, 2020 · 1 comment
Labels
improvement standard library Area: Standard library umbrella

Comments

@swift-ci
Copy link
Collaborator

swift-ci commented Nov 3, 2020

Previous ID SR-13816
Radar rdar://problem/70998651
Original Reporter laclouis5 (JIRA User)
Type Improvement
Additional Detail from JIRA
Votes 0
Component/s Standard Library
Labels Improvement
Assignee None
Priority Medium

md5: 428272cf422670a09b2e579ae777d8bf

Issue Description:

Currently FlattenSequence does not conditionally conform to LazySequenceProtocol when its base does, however, this behavior is supported through this implementation in the standard library:

extension LazySequenceProtocol where Element: Sequence {
  /// Returns a lazy sequence that concatenates the elements of this sequence of
  /// sequences.
  @inlinable // lazy-performance
  public __consuming func joined() -> LazySequence<FlattenSequence<Elements>> {
    return FlattenSequence(_base: elements).lazy
  }
}

This is an uncommon and convoluted way to add lazy behavior to FlattenSequence (when base does), the classic approach in the standard library is the following one:

extension Slice: LazySequenceProtocol where Base: LazySequenceProtocol { }
extension ReversedCollection: LazySequenceProtocol where Base: LazySequenceProtocol { }

This minor issue may feel awkward because the returning type of someSequenceOfSequence.lazy.joined() is not FlattenSequence<LazySequence<...>> as expected but LazySequence<FlattenSequence<...>>.
Fixing this would reduce the number of overloads of the joined() method to 1 and make the standard library more consistent.

@typesanitizer
Copy link

@swift-ci create

@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
improvement standard library Area: Standard library umbrella
Projects
None yet
Development

No branches or pull requests

2 participants