Uploaded image for project: 'Swift'
  1. Swift
  2. SR-13816

FlattenSequence should conform to LazySequenceProtocol when Base does

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Open
    • Priority: Medium
    • Resolution: Unresolved
    • Component/s: Standard Library
    • Labels:
      None

      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.

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            laclouis5 Louis Lac
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated: