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

CTMacUser/swift-algorithms

This branch is 9 commits ahead of, 150 commits behind apple/swift-algorithms:main.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

a0a59ff · Nov 13, 2020

History

43 Commits
Oct 12, 2020
Nov 13, 2020
Nov 13, 2020
Nov 13, 2020
Oct 21, 2020
Oct 16, 2020
Oct 23, 2020
Oct 7, 2020
Oct 7, 2020
Oct 7, 2020
Oct 19, 2020
Nov 13, 2020

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

Other useful operations

  • chunked(by:), chunked(on:): Eager and lazy operations that break a collection into chunks based on either a binary predicate or when the result of a projection changes.
  • indexed(): Iterate over tuples of a collection's indices and elements.
  • trimming(where:): Returns a slice by trimming elements from a collection's start and end.
  • mergeSorted(with:keeping:by:), mergeSorted(with:keeping:): Eager and lazy operations that take another sequence, assume that both the given sequence and the receiver are sorted according to the given predicate (defaults to <), and returns the given subset of the sequences' merger (also sorted).

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%