Skip to content

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

License

Notifications You must be signed in to change notification settings

toddthomas/swift-algorithms

This branch is 1 commit ahead of, 76 commits behind apple/swift-algorithms:main.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

3f531ed · Mar 26, 2021
Oct 12, 2020
Mar 24, 2021
Mar 24, 2021
Mar 26, 2021
Oct 21, 2020
Feb 26, 2021
Oct 7, 2020
Oct 7, 2020
Oct 7, 2020
Oct 19, 2020
Mar 24, 2021

Repository files navigation

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

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

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Swift 100.0%