Skip to content

[Containers] Prototype BorrowingSequence/Container operations #611

@natecook1000

Description

@natecook1000

This is a list of the existing standard library and Swift Algorithms operations that are defined for sequences and/or collections, broken down by where they can be implemented with the existing Container design. We'll keep the list updated as we implement these for borrowing sequences, borrowing iterators, and containers in the ContainersPreview module.

BorrowingSequence methods

  • contains(_:) / contains(where:)
  • allSatisfy(_:)
  • reduce(_:_:)
  • reduce(into:_:)
  • forEach(_:)
  • elementsEqual(_:)
  • elementsEqual(_:by:)
  • starts(with:)
  • starts(with:by:)
  • lexicographicallyPrecedes(_:)
  • lexicographicallyPrecedes(_:by:)
  • count(where:)

BorrowingIteratorProtocol methods

  • map(_:)
  • compactMap(_:)
  • flatMap(_:)
  • filter(_:)
  • compacted()
  • reductions(_:)
  • reductions(_:_:)
  • reductions(into:_:)
  • prefix(_:)
  • prefix(while:)
  • suffix(_)
  • dropFirst(_:)
  • dropLast(_:)
  • drop(while:)
  • trimming(while:)
  • trim(while:)
  • trimmingPrefix(while:)
  • trimPrefix(while:)
  • trimmingSuffix(while:)
  • trimSuffix(while:)
  • suffix(while:)
  • enumerated() (result type has tuple element)
  • product(_:_:)† (result type has tuple element)
  • chain(_:_:)† (merges two lifetimes — possible? Container-only?)
  • cycled()
  • cycled(times:)
  • striding(by:)

Container methods

  • first(where:)
  • firstNonNil(_:)
  • min()
  • max()
  • min(count:)
  • max(count:)
  • minAndMax()
  • randomElement()
  • reversed() (requires bidirectionality)
  • combinations(ofCount:)† (requires O(n) storage for indices)
  • permutations(ofCount:)† (requires O(n) storage for indices)
  • uniquePermutations(ofCount:)† (requires O(n) storage for indices)
  • adjacentPairs()† (result type has tuple element)
  • endOfPrefix(while:)
  • startOfSuffix(while:)
  • indexed()
  • partitioningIndex(where:)

Consuming only ?

Both sorting and shuffling imply consuming (or copying) the existing sequence
to produce a new version (though shuffled can be implemented with O(n) storage
by shuffling the keys).

  • sorted()
  • shuffled()
  • keyed(by:)
  • keyed(by:resolvingConflictsWith:)
  • grouped(by:)
  • partitioned(by:)
  • uniqued()
  • uniqued(on:)
  • randomSample(count:)
  • randomStableSample(count:)

Uses sequence as element

split and join both require sequences as the element type, on opposite
sides of the operation. split needs to produce a sequence of sequences, whereas
joined starts with a sequence of sequences.

  • split(maxSplits:omittingEmptySubsequences:whereSeparator:)
  • split(separator:maxSplits:omittingEmptySubsequences:)
  • interspersed(with:)
  • joined()
  • joined(separator:)
  • joined(by:)
  • windows(ofCount:)
  • chunks(ofCount:)
  • evenlyChunked(in:)
  • chunked(by:)
  • chunked(on:)

In-place mutation

  • sort()
  • stablePartition(by:)
  • stablePartition(subrange:by:)
  • partition(by:)
  • partition(subrange:by:)
  • rotate(toStartAt:)
  • rotate(subrange:toStartAt:)
  • reverse(subrange:)

†: Swift Algorithms Methods

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions