Skip to content

Commit

Permalink
add some feature, add IdentifiedArray
Browse files Browse the repository at this point in the history
Signed-off-by: MikePackard <[email protected]>
  • Loading branch information
NguyenPhongVN committed Mar 16, 2024
1 parent 1657fb3 commit 3c74377
Show file tree
Hide file tree
Showing 78 changed files with 3,374 additions and 719 deletions.
43 changes: 0 additions & 43 deletions .github/workflows/static.yml

This file was deleted.

20 changes: 20 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
.build
DerivedData
/.previous-build
xcuserdata
.DS_Store
*~
\#*
.\#*
.*.sw[nop]
*.xcscmblueprint
/default.profraw
*.xcodeproj
Utilities/Docker/*.tar.gz
.swiftpm
Package.resolved
/build
*.pyc
.docc-build
.vscode
Utilities/InstalledSwiftPMConfiguration/config.json
7 changes: 0 additions & 7 deletions .swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata

This file was deleted.

Binary file not shown.
Binary file not shown.

This file was deleted.

This file was deleted.

134 changes: 75 additions & 59 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -1,61 +1,77 @@
{
"object": {
"pins": [
{
"package": "CwlCatchException",
"repositoryURL": "https://github.com/mattgallagher/CwlCatchException.git",
"state": {
"branch": null,
"revision": "35f9e770f54ce62dd8526470f14c6e137cef3eea",
"version": "2.1.1"
}
},
{
"package": "CwlPreconditionTesting",
"repositoryURL": "https://github.com/mattgallagher/CwlPreconditionTesting.git",
"state": {
"branch": null,
"revision": "fb7a26374e8570ff5c68142e5c83406d6abae0d8",
"version": "2.0.2"
}
},
{
"package": "Nimble",
"repositoryURL": "https://github.com/Quick/Nimble.git",
"state": {
"branch": null,
"revision": "c93f16c25af5770f0d3e6af27c9634640946b068",
"version": "9.2.1"
}
},
{
"package": "Quick",
"repositoryURL": "https://github.com/Quick/Quick.git",
"state": {
"branch": null,
"revision": "bd86ca0141e3cfb333546de5a11ede63f0c4a0e6",
"version": "4.0.0"
}
},
{
"package": "SwiftDocCPlugin",
"repositoryURL": "https://github.com/apple/swift-docc-plugin",
"state": {
"branch": null,
"revision": "9b1258905c21fc1b97bf03d1b4ca12c4ec4e5fda",
"version": "1.2.0"
}
},
{
"package": "SymbolKit",
"repositoryURL": "https://github.com/apple/swift-docc-symbolkit",
"state": {
"branch": null,
"revision": "b45d1f2ed151d057b54504d653e0da5552844e34",
"version": "1.0.0"
}
}
]
},
"version": 1
"pins" : [
{
"identity" : "cwlcatchexception",
"kind" : "remoteSourceControl",
"location" : "https://github.com/mattgallagher/CwlCatchException.git",
"state" : {
"revision" : "3ef6999c73b6938cc0da422f2c912d0158abb0a0",
"version" : "2.2.0"
}
},
{
"identity" : "cwlpreconditiontesting",
"kind" : "remoteSourceControl",
"location" : "https://github.com/mattgallagher/CwlPreconditionTesting.git",
"state" : {
"revision" : "2ef56b2caf25f55fa7eef8784c30d5a767550f54",
"version" : "2.2.1"
}
},
{
"identity" : "nimble",
"kind" : "remoteSourceControl",
"location" : "https://github.com/Quick/Nimble.git",
"state" : {
"revision" : "c93f16c25af5770f0d3e6af27c9634640946b068",
"version" : "9.2.1"
}
},
{
"identity" : "quick",
"kind" : "remoteSourceControl",
"location" : "https://github.com/Quick/Quick.git",
"state" : {
"revision" : "bd86ca0141e3cfb333546de5a11ede63f0c4a0e6",
"version" : "4.0.0"
}
},
{
"identity" : "swift-collections",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-collections",
"state" : {
"revision" : "94cf62b3ba8d4bed62680a282d4c25f9c63c2efb",
"version" : "1.1.0"
}
},
{
"identity" : "swift-docc-plugin",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-docc-plugin",
"state" : {
"revision" : "26ac5758409154cc448d7ab82389c520fa8a8247",
"version" : "1.3.0"
}
},
{
"identity" : "swift-docc-symbolkit",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-docc-symbolkit",
"state" : {
"revision" : "b45d1f2ed151d057b54504d653e0da5552844e34",
"version" : "1.0.0"
}
},
{
"identity" : "swift-identified-collections",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-identified-collections",
"state" : {
"revision" : "d1e45f3e1eee2c9193f5369fa9d70a6ddad635e8",
"version" : "1.0.0"
}
}
],
"version" : 2
}
29 changes: 11 additions & 18 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.8
// swift-tools-version:5.10
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription
Expand All @@ -8,35 +8,28 @@ let package = Package(
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
.library(
name: "Transform",
targets: ["Transform"]),
.library(
name: "DataStructures",
targets: ["DataStructures"]),
.library(
name: "Builder",
targets: ["Builder"]),
name: "SwiftExtension",
targets: ["SwiftExtension"]),
],
dependencies: [
// Dependencies declare other packages that this package depends on.
.package(url: "https://github.com/Quick/Quick.git", from: "4.0.0"),
.package(url: "https://github.com/Quick/Nimble.git", from: "9.2.0"),
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.1.0"),
.package(url: "https://github.com/apple/swift-collections", from: "1.0.2"),
.package(url: "https://github.com/pointfreeco/swift-identified-collections", from: "1.0.0"),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages this package depends on.
.target(
name: "Transform",
dependencies: []),
.target(
name: "DataStructures",
dependencies: []),
.target(
name: "Builder",
dependencies: []),
name: "SwiftExtension",
dependencies: [
.product(name: "IdentifiedCollections", package: "swift-identified-collections"),
.product(name: "OrderedCollections", package: "swift-collections"),
]),
.testTarget(
name: "UnitTests",
dependencies: ["DataStructures", "Transform", "Quick", "Nimble"]),
dependencies: ["Quick", "Nimble"]),
]
)
53 changes: 53 additions & 0 deletions Sources/AsyncExt/AnyAsyncSequence.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import Foundation

/// A type erased `AsyncSequence`
///
/// This type allows you to create APIs that return an `AsyncSequence` that allows consumers to iterate over the sequence, without exposing the sequence's underlyin type.
/// Typically, you wouldn't actually initialize this type yourself, but instead create one using the `.eraseToAnyAsyncSequence()` operator also provided with this package.
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
public struct AnyAsyncSequence<Element>: AsyncSequence {

// MARK: - Initializers

/// Create an `AnyAsyncSequence` from an `AsyncSequence` conforming type
/// - Parameter sequence: The `AnySequence` type you wish to erase
public init<T: AsyncSequence>(_ sequence: T) where T.Element == Element {
makeAsyncIteratorClosure = { AnyAsyncIterator(sequence.makeAsyncIterator()) }
}

public struct AnyAsyncIterator: AsyncIteratorProtocol {
private let nextClosure: () async throws -> Element?

public init<T: AsyncIteratorProtocol>(_ iterator: T) where T.Element == Element {
var iterator = iterator
nextClosure = { try await iterator.next() }
}

public func next() async throws -> Element? {
try await nextClosure()
}
}

// MARK: - AsyncSequence

public typealias Element = Element

public typealias AsyncIterator = AnyAsyncIterator

public func makeAsyncIterator() -> AsyncIterator {
AnyAsyncIterator(makeAsyncIteratorClosure())
}

private let makeAsyncIteratorClosure: () -> AsyncIterator

}

@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
public extension AsyncSequence {

/// Create a type erased version of this sequence
/// - Returns: The sequence, wrapped in an `AnyAsyncSequence`
func eraseToAnyAsyncSequence() -> AnyAsyncSequence<Element> {
AnyAsyncSequence(self)
}
}
Loading

0 comments on commit 3c74377

Please sign in to comment.