3

Github GitHub - apple/swift-algorithms: Swift Algorithms is an open-source packa...

 3 years ago
source link: https://github.com/apple/swift-algorithms
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Swift Algorithms

Swift Algorithms is an open-source package of sequence and collection algorithms, along with their related types.

Read more about the package, and the intent behind it, in the announcement on swift.org.

Contents

Combinations / permutations

Mutating algorithms

Combining collections

  • chain(_:_:): Concatenates two collections with the same element type.
  • product(_:_:): Iterates over all the pairs of two collections; equivalent to nested for-in loops.
  • cycled(), cycled(times:): Repeats the elements of a collection forever or a set number of times.

Subsetting operations

Partial sorting

Other useful operations

Adding Swift Algorithms as a Dependency

To use the Algorithms library in a SwiftPM project, add the following line to the dependencies in your Package.swift file:

.package(url: "https://github.com/apple/swift-algorithms", from: "0.0.1"),

Because Algorithms is under active development, source-stability is only guaranteed within minor versions (e.g. between 0.0.3 and 0.0.4). If you don't want potentially source-breaking package updates, use this dependency specification instead:

.package(url: "https://github.com/apple/swift-algorithms", .upToNextMinor(from: "0.0.1")),

Finally, include "Algorithms" as a dependency for your executable target:

let package = Package(
    // name, platforms, products, etc.
    dependencies: [
        .package(url: "https://github.com/apple/swift-algorithms", from: "0.0.1"),
        // other dependencies
    ],
    targets: [
        .target(name: "<target>", dependencies: [
            .product(name: "Algorithms", package: "swift-algorithms"),
        ]),
        // other targets
    ]
)

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK