[ContainersPreview] Spin off Producer.collect algorithms into a separate file for easy lookups

This commit is contained in:
Karoy Lorentey committed 2026-03-13 10:41:04 -07:00
1 parent c4760ec21a
commit bf18a48983
2 files changed
+33 -17

No files matched your search

@@ -0,0 +1,33 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift Collections open source project
//
// Copyright (c) 2026 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
//
// SPDX-License-Identifier: Apache-2.0 WITH Swift-exception
//
//===----------------------------------------------------------------------===//
#if compiler(>=6.2) && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW
@available(SwiftStdlib 5.0, *)
extension Producer where Self: ~Copyable & ~Escapable {
@inlinable
public consuming func collect<R: DynamicContainer<Element>>(
into container: R.Type = R.self
) throws(ProducerError) -> R {
try R(from: &self)
}
@inlinable
public consuming func collect(
into container: inout some DynamicContainer<Element>
) throws(ProducerError) {
try container.append(from: &self)
}
}
#endif
@@ -274,21 +274,4 @@ extension Producer where Self: ~Copyable & ~Escapable {
}
}
@available(SwiftStdlib 5.0, *)
extension Producer where Self: ~Copyable & ~Escapable {
@inlinable
public consuming func collect<R: DynamicContainer<Element>>(
into container: R.Type = R.self
) throws(ProducerError) -> R {
try R(from: &self)
}
@inlinable
public consuming func collect(
into container: inout some DynamicContainer<Element>
) throws(ProducerError) {
try container.append(from: &self)
}
}
#endif