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

Lazy filter runs in unexpected order

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Medium
    • Resolution: Done
    • Component/s: Standard Library
    • Labels:
      None
    • Environment:

      Xcode 11.2.1

      Description

      For the following code:

      var array = ["1", "2", "3"]
      
      
      let filtered = array.lazy
          .filter({ _ in
              print("A")
              return true
          }).filter { _ in
              print("B")
              return true
      }
      
      _ = Array(filtered)

       
      Actual Results:

      B
      A
      B
      A
      B
      A
      

       

       Expected Results: 

      A
      B
      A
      B
      A
      B
      

        

      I would expect a cascade behaviour of A filtering before B*. However, this prints:

      *Not to confuse with non lazy behaviour of AAABBB which is indeed correct

       

       

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            dtorres Diego Torres
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: