Skip to main content
100%

Gist b7643abc7d460e1673981d3f41bb9b40

✓ Published0🌍 Public
MMoximillian
Last edited Jun 11, 2018
Created on Jun 7, 2018

This example demonstrates a Swift language extension that optimizes the `reversed()` operation on lazy collections. It defines a `ReversedCollectionProtocol` for bidirectional collections, and an extension that lets reversing a lazy reversed collection return a lazy representation of the original, avoiding unnecessary materialization. The code uses Swift generics and associated types (`Elements.Base`) to express this optimization, and notes a fallback using parametrized extensions for Swift versions prior to 4.2.

AI-generated description

Similar vizzes