This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
struct RecursiveModifier<Data: Collection, Transformed: View>: ViewModifier { | |
let data: Data | |
let transform: (Data.Element, AnyView) -> Transformed | |
func body(content: Content) -> some View { | |
var subsequence = data[...] | |
if let first = subsequence.popFirst() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct AsyncWrappedSequence<Base: Sequence>: AsyncSequence { | |
typealias Element = Base.Element | |
struct AsyncIterator<BaseIterator>: AsyncIteratorProtocol where BaseIterator == Base.Iterator { | |
var base: BaseIterator | |
mutating func next() async -> BaseIterator.Element? { | |
base.next() | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct AnyAsyncSequence<Element>: AsyncSequence { | |
struct AnyAsyncIterator: AsyncIteratorProtocol { | |
private let _next: () async throws -> Element? | |
init<Base: AsyncSequence>(_ base: Base) where Base.Element == Element { | |
var baseIterator = base.makeAsyncIterator() | |
self._next = { try await baseIterator.next() } | |
} | |
func next() async throws -> Element? { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct InterleavedSequence<First: Sequence, Second: Sequence>: Sequence where First.Element == Second.Element { | |
let first: First | |
let second: Second | |
init(first: First, second: Second) { | |
self.first = first | |
self.second = second | |
} | |
func makeIterator() -> Iterator { |