Nate Cook bd64bef3d2 Rename sortedPrefix methods (#77)
This renames sortedPrefix to min(count:), adds max(count:),
and moves both methods down to Sequence.

In order to still provide the optimization when `count` is close to
a collection's length, we include a Collection-specific overload of
all methods. These won't be accessed when in a Sequence-generic context,
but it's the best we can do without adding these methods as protocol
requirements.
2021-02-26 13:57:55 -06:00
2021-02-26 13:57:55 -06:00
2021-02-26 13:57:55 -06:00
2020-10-21 15:36:12 -05:00
2020-10-07 10:24:43 -05:00
2020-10-07 10:24:43 -05:00
2020-10-07 10:24:43 -05:00
2021-02-26 13:57:55 -06:00

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

  • chunked(by:), chunked(on:), chunks(ofCount:): Eager and lazy operations that break a collection into chunks based on either a binary predicate or when the result of a projection changes or chunks of a given count.
  • indexed(): Iterate over tuples of a collection's indices and elements.
  • interspersed(with:): Place a value between every two elements of a sequence.
  • trimming(while:): Returns a slice by trimming elements from a collection's start and end.
  • windows(ofCount:): Breaks a collection into overlapping subsequences where elements are slices from the original collection.
  • striding(by:): Returns every nth element of a collection.

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
    ]
)
S
Description
Mirror of github.com/apple/swift-algorithms
Readme Apache-2.0
2.3 MiB
0 Stars 1 Watchers 0 Forks
Languages
Swift 99.8%
Shell 0.2%