profile
viewpoint
If you are wondering where the data of this site comes from, please visit https://api.github.com/users/schlagelk/events. GitMemory does not store any data, but only uses NGINX to cache data for a period of time. The idea behind GitMemory is simply to give users a better reading experience.

schlagelk/Mariachi 9

🎺 Pull Request Review Reminders for MSFT Teams

schlagelk/APODtv 1

a tvOS application that fetches the always spectacular APOD from NASA.

schlagelk/checkcheetah 1

Runs Your Checks By Commenting

schlagelk/Jazz-Hands 1

Vanilla user auth using Slim, Twig, Bootstrap and Eloquent ORM

schlagelk/AppUpdater 0

Automatically update open source macOS apps from GitHub releases.

schlagelk/blueshft 0

An experimental app which uses Bluetooth beacons, social authentication and maps to display college tour info.

schlagelk/calendar-heatmap 0

📊 Calendar heatmap graph

schlagelk/detecting_objects_in_still_images 0

fork of https://developer.apple.com/documentation/vision/detecting_objects_in_still_images

schlagelk/docs 0

The open-source repo for docs.github.com

startedorta/specs-repo-git-scanner

started time in an hour

PR opened apple/swift-argument-parser

Hide option group with new OptionGroup constructor

Second PR that is needed to fix --help for SwiftPM

Related PRs:

SwiftPM ArgumentParser

Checklist

  • [x] I've added at least one test that validates that my change is working, if appropriate
  • [x] I've followed the code style of the rest of the project
  • [x] I've read the Contribution Guidelines
  • [x] I've updated the documentation if necessary
+155 -5

0 comment

7 changed files

pr created time in 2 hours

create barnchapple/swift-argument-parser

branch : hideOptionGroup

created branch time in 2 hours

startedv-byte-cpu/sx

started time in 5 hours

push eventapple/swift-argument-parser

Miguel Perez

commit sha 7478e4473edc937e02454ea1bde1853e7be35f6b

Added test and removed flag search loop

view details

push time in 5 hours

issue commentapple/swift-argument-parser

Option parsing from environment variables

still waiting😭

KyleLeneau

comment created time in 6 hours

push eventapple/swift-protobuf

Thomas Van Lenten

commit sha 3a4b54d617ee953a82fbf04405d5d8cf9083f416

Don't walk off the end of the buffer during a unicode bytes decode. Preflight the check instead of checking during the loop (which wasn't advancing).

view details

push time in 7 hours

PR merged apple/swift-protobuf

Reviewers
Don't walk off the end of the buffer during a unicode bytes decode.

Preflight the check instead of checking during the loop (which wasn't advancing).

+9 -3

0 comment

3 changed files

thomasvl

pr closed time in 7 hours

issue closedapple/swift-algorithms

Using GitHub Bots?

<!-- Thanks for contributing to Swift Algorithms!

Before you submit your issue, please replace the paragraph
below with information about your proposed feature.

-->

GitHub has lots of really handy bots that integrate with pushed commits and PR actions, as well as GitHub Actions CI. I have used GitHub’s bots in my own projects and found them very secure, helpful and easy to integrate.

I have raised #133 re: [ImgBot] but I am open to your feedback on more general Bot integrations as well.

Thanks.

closed time in 8 hours

LemonSpike

issue commentapple/swift-algorithms

Using GitHub Bots?

We're just sticking with Swift CI for now. Thanks, @LemonSpike!

LemonSpike

comment created time in 8 hours

Pull request review commentapple/swift-algorithms

Add new heading and description for partitionIndex 🤷‍♂️.

 Read more about the package, and the intent behind it, in the [announcement on s - [`split(maxSplits:omittingEmptySubsequences:whereSeparator)`, `split(separator:maxSplits:omittingEmptySubsequences)`](https://github.com/apple/swift-algorithms/blob/main/Guides/LazySplit.md): Lazy versions of the Standard Library's eager operations that split sequences and collections into subsequences separated by the specified separator element. - [`windows(ofCount:)`](https://github.com/apple/swift-algorithms/blob/main/Guides/Windows.md): Breaks a collection into overlapping subsequences where elements are slices from the original collection. +#### Binary Search Partitions

Let's add it to "Other useful operations" for now, thanks!

LemonSpike

comment created time in 8 hours

pull request commentapple/swift-argument-parser

Exclude supercommands from help

@miggs597 Thanks for working on this! After looking further, it doesn't look like this actually needs to be configurable. generateSections really only needs to look at commandStack.last to generate its different help options. The only arguments and options that a command really needs to print are those actually defined in the command either directly or included via @OptionGroup.

You'll still need to use your custom mirror to suppress SwiftToolOptions from being displayed in package init until there's #267 is implemented, but this will help make that possible as well.

miggs597

comment created time in 9 hours

PR opened apple/swift-protobuf

Reviewers
Don't walk off the end of the buffer during a unicode bytes decode.

Preflight the check instead of checking during the loop (which wasn't advancing).

+9 -3

0 comment

3 changed files

pr created time in 9 hours

push eventapple/swift-protobuf

Thomas Van Lenten

commit sha 3811784a98e3d9a33d99c6db4e923fefb532d671

Only trigger conflicting oneof if a value is decoded. This lets things like JSON that can have `null` as the value not count as setting the field and thus not causing the conflict per the new conformance test. Fixes #1133

view details

Thomas Van Lenten

commit sha 7c36b52ca9ad4cb83696c929c7e9ccb610e80561

Update the generated files.

view details

Thomas Van Lenten

commit sha 324f4cbfdf4c11335547696f2f271bae388b0390

Update the generated_swift_names_ files.

view details

push time in 10 hours

issue closedapple/swift-protobuf

New conformance test failure

Looks like upstream got a new conformance test around oneofs fields and setting them to null that is failing.

Required.Proto3.JsonInput.OneofFieldNullSecond.JsonOutput
Required.Proto3.JsonInput.OneofFieldNullSecond.ProtobufOutput

closed time in 10 hours

thomasvl

pull request commentapple/swift-protobuf

Change oneof enforcement to allow null

Nice! Much simpler than I expected.

Yea, I look a peek thinking I was going to need to track some state in the decoder, but realized a small reordering should be able to do it.

thomasvl

comment created time in 10 hours

Pull request review commentapple/swift-algorithms

Introduce `adjacentPairs`

+//===----------------------------------------------------------------------===//+//+// This source file is part of the Swift Algorithms open source project+//+// Copyright (c) 2021 Apple Inc. and the Swift project authors+// Licensed under Apache License v2.0 with Runtime Library Exception+//+// See https://swift.org/LICENSE.txt for license information+//+//===----------------------------------------------------------------------===//++extension Sequence {+  /// Creates a sequence of adjacent pairs of elements from this sequence.+  ///+  /// In the `AdjacentPairsSequence` returned by this method, the elements of+  /// the *i*th pair are the *i*th and *(i+1)*th elements of the underlying+  /// sequence.+  /// The following example uses the `adjacentPairs()` method to iterate over+  /// adjacent pairs of integers:+  ///+  ///    for pair in (1...5).adjacentPairs() {+  ///        print(pair)+  ///    }+  ///    // Prints "(1, 2)"+  ///    // Prints "(2, 3)"+  ///    // Prints "(3, 4)"+  ///    // Prints "(4, 5)"+  @inlinable+  public func adjacentPairs() -> AdjacentPairsSequence<Self> {+    AdjacentPairsSequence(base: self)+  }+}++extension Collection {+  /// A collection of adjacent pairs of elements built from an underlying collection.+  ///+  /// In an `AdjacentPairsCollection`, the elements of the *i*th pair are the *i*th+  /// and *(i+1)*th elements of the underlying sequence. The following example+  /// uses the `adjacentPairs()` method to iterate over adjacent pairs of+  /// integers:+  /// ```+  /// for pair in (1...5).adjacentPairs() {+  ///     print(pair)+  /// }+  /// // Prints "(1, 2)"+  /// // Prints "(2, 3)"+  /// // Prints "(3, 4)"+  /// // Prints "(4, 5)"+  /// ```+  @inlinable+  public func adjacentPairs() -> AdjacentPairsCollection<Self> {+    AdjacentPairsCollection(base: self)+  }+}++/// A sequence of adjacent pairs of elements built from an underlying sequence.+///+/// In an `AdjacentPairsSequence`, the elements of the *i*th pair are the *i*th+/// and *(i+1)*th elements of the underlying sequence. The following example+/// uses the `adjacentPairs()` method to iterate over adjacent pairs of+/// integers:+/// ```+/// for pair in (1...5).adjacentPairs() {+///     print(pair)+/// }+/// // Prints "(1, 2)"+/// // Prints "(2, 3)"+/// // Prints "(3, 4)"+/// // Prints "(4, 5)"+/// ```+public struct AdjacentPairsSequence<Base: Sequence> {+  @usableFromInline+  internal let base: Base++  /// Creates an instance that makes pairs of adjacent elements from `base`.+  @inlinable+  internal init(base: Base) {+    self.base = base+  }+}++extension AdjacentPairsSequence {+  public struct Iterator {+    @usableFromInline+    internal var base: Base.Iterator++    @usableFromInline+    internal var previousElement: Base.Element?++    @inlinable+    internal init(base: Base.Iterator) {+      self.base = base+    }+  }+}++extension AdjacentPairsSequence.Iterator: IteratorProtocol {+  public typealias Element = (Base.Element, Base.Element)++  @inlinable+  public mutating func next() -> Element? {+    if previousElement == nil {+      previousElement = base.next()+    }++    guard let previous = previousElement, let next = base.next() else {+      return nil+    }++    previousElement = next+    return (previous, next)+  }+}++extension AdjacentPairsSequence: Sequence {+  @inlinable+  public func makeIterator() -> Iterator {+    Iterator(base: base.makeIterator())+  }++  @inlinable+  public var underestimatedCount: Int {+    Swift.max(0, base.underestimatedCount - 1)+  }+}++/// A collection of adjacent pairs of elements built from an underlying collection.+///+/// In an `AdjacentPairsCollection`, the elements of the *i*th pair are the *i*th+/// and *(i+1)*th elements of the underlying sequence. The following example+/// uses the `adjacentPairs()` method to iterate over adjacent pairs of+/// integers:+/// ```+/// for pair in (1...5).adjacentPairs() {+///     print(pair)+/// }+/// // Prints "(1, 2)"+/// // Prints "(2, 3)"+/// // Prints "(3, 4)"+/// // Prints "(4, 5)"+/// ```+public struct AdjacentPairsCollection<Base: Collection> {+  @usableFromInline+  internal let base: Base++  public let startIndex: Index++  @inlinable+  internal init(base: Base) {+    self.base = base++    // Precompute `startIndex` to ensure O(1) behavior,+    // avoiding indexing past `endIndex`+    let start = base.startIndex+    let end = base.endIndex+    let second = start == end ? start : base.index(after: start)+    self.startIndex = Index(first: start, second: second)+  }+}++extension AdjacentPairsCollection {+  public typealias Iterator = AdjacentPairsSequence<Base>.Iterator++  @inlinable+  public func makeIterator() -> Iterator {+    Iterator(base: base.makeIterator())+  }+}++extension AdjacentPairsCollection {+  public struct Index: Comparable {+    @usableFromInline+    internal var first: Base.Index+    +    @usableFromInline+    internal var second: Base.Index++    @inlinable+    internal init(first: Base.Index, second: Base.Index) {+      self.first = first+      self.second = second+    }++    @inlinable+    public static func < (lhs: Index, rhs: Index) -> Bool {+      (lhs.first, lhs.second) < (rhs.first, rhs.second)+    }

You should only need to compare one of the two underlying indices here instead of both, and the same applies to ==.

mpangburn

comment created time in 12 hours

Pull request review commentapple/swift-algorithms

Introduce `adjacentPairs`

+//===----------------------------------------------------------------------===//+//+// This source file is part of the Swift Algorithms open source project+//+// Copyright (c) 2021 Apple Inc. and the Swift project authors+// Licensed under Apache License v2.0 with Runtime Library Exception+//+// See https://swift.org/LICENSE.txt for license information+//+//===----------------------------------------------------------------------===//++extension Sequence {+  /// Creates a sequence of adjacent pairs of elements from this sequence.+  ///+  /// In the `AdjacentPairsSequence` returned by this method, the elements of+  /// the *i*th pair are the *i*th and *(i+1)*th elements of the underlying+  /// sequence.+  /// The following example uses the `adjacentPairs()` method to iterate over+  /// adjacent pairs of integers:+  ///+  ///    for pair in (1...5).adjacentPairs() {+  ///        print(pair)+  ///    }+  ///    // Prints "(1, 2)"+  ///    // Prints "(2, 3)"+  ///    // Prints "(3, 4)"+  ///    // Prints "(4, 5)"+  @inlinable+  public func adjacentPairs() -> AdjacentPairsSequence<Self> {+    AdjacentPairsSequence(base: self)+  }+}++extension Collection {+  /// A collection of adjacent pairs of elements built from an underlying collection.+  ///+  /// In an `AdjacentPairsCollection`, the elements of the *i*th pair are the *i*th+  /// and *(i+1)*th elements of the underlying sequence. The following example+  /// uses the `adjacentPairs()` method to iterate over adjacent pairs of+  /// integers:+  /// ```+  /// for pair in (1...5).adjacentPairs() {+  ///     print(pair)+  /// }+  /// // Prints "(1, 2)"+  /// // Prints "(2, 3)"+  /// // Prints "(3, 4)"+  /// // Prints "(4, 5)"+  /// ```+  @inlinable+  public func adjacentPairs() -> AdjacentPairsCollection<Self> {+    AdjacentPairsCollection(base: self)+  }+}++/// A sequence of adjacent pairs of elements built from an underlying sequence.+///+/// In an `AdjacentPairsSequence`, the elements of the *i*th pair are the *i*th+/// and *(i+1)*th elements of the underlying sequence. The following example+/// uses the `adjacentPairs()` method to iterate over adjacent pairs of+/// integers:+/// ```+/// for pair in (1...5).adjacentPairs() {+///     print(pair)+/// }+/// // Prints "(1, 2)"+/// // Prints "(2, 3)"+/// // Prints "(3, 4)"+/// // Prints "(4, 5)"+/// ```+public struct AdjacentPairsSequence<Base: Sequence> {+  @usableFromInline+  internal let base: Base++  /// Creates an instance that makes pairs of adjacent elements from `base`.+  @inlinable+  internal init(base: Base) {+    self.base = base+  }+}++extension AdjacentPairsSequence {+  public struct Iterator {+    @usableFromInline+    internal var base: Base.Iterator++    @usableFromInline+    internal var previousElement: Base.Element?++    @inlinable+    internal init(base: Base.Iterator) {+      self.base = base+    }+  }+}++extension AdjacentPairsSequence.Iterator: IteratorProtocol {+  public typealias Element = (Base.Element, Base.Element)++  @inlinable+  public mutating func next() -> Element? {+    if previousElement == nil {+      previousElement = base.next()+    }++    guard let previous = previousElement, let next = base.next() else {+      return nil+    }++    previousElement = next+    return (previous, next)+  }+}++extension AdjacentPairsSequence: Sequence {+  @inlinable+  public func makeIterator() -> Iterator {+    Iterator(base: base.makeIterator())+  }++  @inlinable+  public var underestimatedCount: Int {+    Swift.max(0, base.underestimatedCount - 1)+  }+}++/// A collection of adjacent pairs of elements built from an underlying collection.+///+/// In an `AdjacentPairsCollection`, the elements of the *i*th pair are the *i*th+/// and *(i+1)*th elements of the underlying sequence. The following example+/// uses the `adjacentPairs()` method to iterate over adjacent pairs of+/// integers:+/// ```+/// for pair in (1...5).adjacentPairs() {+///     print(pair)+/// }+/// // Prints "(1, 2)"+/// // Prints "(2, 3)"+/// // Prints "(3, 4)"+/// // Prints "(4, 5)"+/// ```+public struct AdjacentPairsCollection<Base: Collection> {+  @usableFromInline+  internal let base: Base++  public let startIndex: Index++  @inlinable+  internal init(base: Base) {+    self.base = base++    // Precompute `startIndex` to ensure O(1) behavior,+    // avoiding indexing past `endIndex`+    let start = base.startIndex+    let end = base.endIndex+    let second = start == end ? start : base.index(after: start)+    self.startIndex = Index(first: start, second: second)+  }+}++extension AdjacentPairsCollection {+  public typealias Iterator = AdjacentPairsSequence<Base>.Iterator++  @inlinable+  public func makeIterator() -> Iterator {+    Iterator(base: base.makeIterator())+  }+}++extension AdjacentPairsCollection {+  public struct Index: Comparable {+    @usableFromInline+    internal var first: Base.Index+    +    @usableFromInline+    internal var second: Base.Index++    @inlinable+    internal init(first: Base.Index, second: Base.Index) {+      self.first = first+      self.second = second+    }++    @inlinable+    public static func < (lhs: Index, rhs: Index) -> Bool {+      (lhs.first, lhs.second) < (rhs.first, rhs.second)+    }+  }+}++extension AdjacentPairsCollection: Collection {+  @inlinable+  public var endIndex: Index {+    switch base.endIndex {+    case startIndex.first, startIndex.second:+      return startIndex+    case let end:+      return Index(first: end, second: end)+    }+  }++  @inlinable+  public subscript(position: Index) -> (Base.Element, Base.Element) {+    (base[position.first], base[position.second])+  }++  @inlinable+  public func index(after i: Index) -> Index {+    let next = base.index(after: i.second)+    return next == base.endIndex+      ? endIndex+      : Index(first: i.second, second: next)+  }++  @inlinable+  public func index(_ i: Index, offsetBy distance: Int) -> Index {+    if distance == 0 {+      return i+    } else if distance > 0 {+      let firstOffsetIndex = base.index(i.first, offsetBy: distance)+      let secondOffsetIndex = base.index(after: firstOffsetIndex)+      return secondOffsetIndex == base.endIndex+        ? endIndex+        : Index(first: firstOffsetIndex, second: secondOffsetIndex)+    } else {+      return i == endIndex+        ? Index(first: base.index(i.first, offsetBy: distance - 1),+                second: base.index(i.first, offsetBy: distance))+        : Index(first: base.index(i.first, offsetBy: distance),+                second: i.first)

You could avoid computing the first and second indices separately here, since you can cheaply compute the firts if you already have the second.

mpangburn

comment created time in 12 hours

Pull request review commentapple/swift-algorithms

Introduce `adjacentPairs`

+//===----------------------------------------------------------------------===//+//+// This source file is part of the Swift Algorithms open source project+//+// Copyright (c) 2021 Apple Inc. and the Swift project authors+// Licensed under Apache License v2.0 with Runtime Library Exception+//+// See https://swift.org/LICENSE.txt for license information+//+//===----------------------------------------------------------------------===//++import XCTest+import Algorithms++final class AdjacentPairsTests: XCTestCase {+  func testZeroElements() {+    let pairs = (0..<0).adjacentPairs()+    XCTAssertEqual(pairs.startIndex, pairs.endIndex)+    XCTAssert(Array(pairs) == [])+  }++  func testOneElement() {+    let pairs = (0..<1).adjacentPairs()+    XCTAssertEqual(pairs.startIndex, pairs.endIndex)+    XCTAssert(Array(pairs) == [])+  }++  func testTwoElements() {+    let pairs = (0..<2).adjacentPairs()+    XCTAssert(Array(pairs) == [(0, 1)])+  }++  func testThreeElements() {+    let pairs = (0..<3).adjacentPairs()+    XCTAssert(Array(pairs) == [(0, 1), (1, 2)])+  }++  func testFourElements() {+    let pairs = (0..<4).adjacentPairs()+    XCTAssert(Array(pairs) == [(0, 1), (1, 2), (2, 3)])+  }++  func testForwardIndexing() {+    let pairs = (1...5).adjacentPairs()+    let expected = [(1, 2), (2, 3), (3, 4), (4, 5)]+    var index = pairs.startIndex+    for iteration in expected.indices {+      XCTAssert(pairs[index] == expected[iteration])+      pairs.formIndex(after: &index)+    }+    XCTAssertEqual(index, pairs.endIndex)+  }++  func testBackwardIndexing() {+    let pairs = (1...5).adjacentPairs()+    let expected = [(4, 5), (3, 4), (2, 3), (1, 2)]+    var index = pairs.endIndex+    for iteration in expected.indices {+      pairs.formIndex(before: &index)+      XCTAssert(pairs[index] == expected[iteration])+    }+    XCTAssertEqual(index, pairs.startIndex)+  }++  func testIndexDistance() {+    let pairSequences = (0...4).map { (0..<$0).adjacentPairs() }++    for pairs in pairSequences {+      for index in pairs.indices.dropLast() {+        let next = pairs.index(after: index)+        XCTAssertEqual(pairs.distance(from: index, to: next), 1)+      }++      XCTAssertEqual(pairs.distance(from: pairs.startIndex, to: pairs.endIndex), pairs.count)+      XCTAssertEqual(pairs.distance(from: pairs.endIndex, to: pairs.startIndex), -pairs.count)+    }+  }++  func testIndexOffsetBy() {+    let pairSequences = (0...4).map { (0..<$0).adjacentPairs() }++    for pairs in pairSequences {+      for index in pairs.indices.dropLast() {+        let next = pairs.index(after: index)+        XCTAssertEqual(pairs.index(index, offsetBy: 1), next)+      }++      XCTAssertEqual(pairs.index(pairs.startIndex, offsetBy: pairs.count), pairs.endIndex)+      XCTAssertEqual(pairs.index(pairs.endIndex, offsetBy: -pairs.count), pairs.startIndex)+    }+  }+}++extension Collection {+  fileprivate static func == <L: Equatable, R: Equatable> (lhs: Self, rhs: Self) -> Bool where Element == (L, R) {+    lhs.count == rhs.count && zip(lhs, rhs).allSatisfy(==)
    lhs.elementsEqual(rhs, by: ==)
mpangburn

comment created time in 6 days

Pull request review commentapple/swift-algorithms

Introduce `adjacentPairs`

+//===----------------------------------------------------------------------===//+//+// This source file is part of the Swift Algorithms open source project+//+// Copyright (c) 2021 Apple Inc. and the Swift project authors+// Licensed under Apache License v2.0 with Runtime Library Exception+//+// See https://swift.org/LICENSE.txt for license information+//+//===----------------------------------------------------------------------===//++import XCTest+import Algorithms++final class AdjacentPairsTests: XCTestCase {+  func testZeroElements() {+    let pairs = (0..<0).adjacentPairs()+    XCTAssertEqual(pairs.startIndex, pairs.endIndex)+    XCTAssert(Array(pairs) == [])+  }++  func testOneElement() {+    let pairs = (0..<1).adjacentPairs()+    XCTAssertEqual(pairs.startIndex, pairs.endIndex)+    XCTAssert(Array(pairs) == [])+  }++  func testTwoElements() {+    let pairs = (0..<2).adjacentPairs()+    XCTAssert(Array(pairs) == [(0, 1)])+  }++  func testThreeElements() {+    let pairs = (0..<3).adjacentPairs()+    XCTAssert(Array(pairs) == [(0, 1), (1, 2)])+  }++  func testFourElements() {+    let pairs = (0..<4).adjacentPairs()+    XCTAssert(Array(pairs) == [(0, 1), (1, 2), (2, 3)])+  }++  func testForwardIndexing() {+    let pairs = (1...5).adjacentPairs()+    let expected = [(1, 2), (2, 3), (3, 4), (4, 5)]+    var index = pairs.startIndex+    for iteration in expected.indices {+      XCTAssert(pairs[index] == expected[iteration])+      pairs.formIndex(after: &index)+    }+    XCTAssertEqual(index, pairs.endIndex)+  }++  func testBackwardIndexing() {+    let pairs = (1...5).adjacentPairs()+    let expected = [(4, 5), (3, 4), (2, 3), (1, 2)]+    var index = pairs.endIndex+    for iteration in expected.indices {+      pairs.formIndex(before: &index)+      XCTAssert(pairs[index] == expected[iteration])+    }+    XCTAssertEqual(index, pairs.startIndex)+  }++  func testIndexDistance() {+    let pairSequences = (0...4).map { (0..<$0).adjacentPairs() }++    for pairs in pairSequences {+      for index in pairs.indices.dropLast() {+        let next = pairs.index(after: index)+        XCTAssertEqual(pairs.distance(from: index, to: next), 1)+      }++      XCTAssertEqual(pairs.distance(from: pairs.startIndex, to: pairs.endIndex), pairs.count)+      XCTAssertEqual(pairs.distance(from: pairs.endIndex, to: pairs.startIndex), -pairs.count)+    }+  }++  func testIndexOffsetBy() {+    let pairSequences = (0...4).map { (0..<$0).adjacentPairs() }++    for pairs in pairSequences {+      for index in pairs.indices.dropLast() {+        let next = pairs.index(after: index)+        XCTAssertEqual(pairs.index(index, offsetBy: 1), next)+      }++      XCTAssertEqual(pairs.index(pairs.startIndex, offsetBy: pairs.count), pairs.endIndex)+      XCTAssertEqual(pairs.index(pairs.endIndex, offsetBy: -pairs.count), pairs.startIndex)+    }+  }

These tests are made redundant by the validateIndexTraversals method that tests whether all index manipulation logic is well-behaved, in an exhaustive manner. Something like this probably covers all edge cases:

func testIndexTraversals() {
  validateIndexTraversals(
    (0..<0).adjacentPairs(),
    (0..<1).adjacentPairs(),
    (0..<2).adjacentPairs(),
    (0..<3).adjacentPairs(),
    (0..<10).adjacentPairs())
}
mpangburn

comment created time in 6 days

Pull request review commentapple/swift-algorithms

Introduce `adjacentPairs`

+//===----------------------------------------------------------------------===//+//+// This source file is part of the Swift Algorithms open source project+//+// Copyright (c) 2021 Apple Inc. and the Swift project authors+// Licensed under Apache License v2.0 with Runtime Library Exception+//+// See https://swift.org/LICENSE.txt for license information+//+//===----------------------------------------------------------------------===//++extension Sequence {+  /// Creates a sequence of adjacent pairs of elements from this sequence.+  ///+  /// In the `AdjacentPairsSequence` returned by this method, the elements of+  /// the *i*th pair are the *i*th and *(i+1)*th elements of the underlying+  /// sequence.+  /// The following example uses the `adjacentPairs()` method to iterate over+  /// adjacent pairs of integers:+  ///+  ///    for pair in (1...5).adjacentPairs() {+  ///        print(pair)+  ///    }+  ///    // Prints "(1, 2)"+  ///    // Prints "(2, 3)"+  ///    // Prints "(3, 4)"+  ///    // Prints "(4, 5)"+  @inlinable+  public func adjacentPairs() -> AdjacentPairsSequence<Self> {+    AdjacentPairsSequence(base: self)+  }+}++extension Collection {+  /// A collection of adjacent pairs of elements built from an underlying collection.+  ///+  /// In an `AdjacentPairsCollection`, the elements of the *i*th pair are the *i*th+  /// and *(i+1)*th elements of the underlying sequence. The following example+  /// uses the `adjacentPairs()` method to iterate over adjacent pairs of+  /// integers:+  /// ```+  /// for pair in (1...5).adjacentPairs() {+  ///     print(pair)+  /// }+  /// // Prints "(1, 2)"+  /// // Prints "(2, 3)"+  /// // Prints "(3, 4)"+  /// // Prints "(4, 5)"+  /// ```+  @inlinable+  public func adjacentPairs() -> AdjacentPairsCollection<Self> {+    AdjacentPairsCollection(base: self)+  }+}++/// A sequence of adjacent pairs of elements built from an underlying sequence.+///+/// In an `AdjacentPairsSequence`, the elements of the *i*th pair are the *i*th+/// and *(i+1)*th elements of the underlying sequence. The following example+/// uses the `adjacentPairs()` method to iterate over adjacent pairs of+/// integers:+/// ```+/// for pair in (1...5).adjacentPairs() {+///     print(pair)+/// }+/// // Prints "(1, 2)"+/// // Prints "(2, 3)"+/// // Prints "(3, 4)"+/// // Prints "(4, 5)"+/// ```+public struct AdjacentPairsSequence<Base: Sequence> {+  @usableFromInline+  internal let base: Base++  /// Creates an instance that makes pairs of adjacent elements from `base`.+  @inlinable+  internal init(base: Base) {+    self.base = base+  }+}++extension AdjacentPairsSequence {+  public struct Iterator {+    @usableFromInline+    internal var base: Base.Iterator++    @usableFromInline+    internal var previousElement: Base.Element?++    @inlinable+    internal init(base: Base.Iterator) {+      self.base = base+    }+  }+}++extension AdjacentPairsSequence.Iterator: IteratorProtocol {+  public typealias Element = (Base.Element, Base.Element)++  @inlinable+  public mutating func next() -> Element? {+    if previousElement == nil {+      previousElement = base.next()+    }++    guard let previous = previousElement, let next = base.next() else {+      return nil+    }++    previousElement = next+    return (previous, next)+  }+}++extension AdjacentPairsSequence: Sequence {+  @inlinable+  public func makeIterator() -> Iterator {+    Iterator(base: base.makeIterator())+  }++  @inlinable+  public var underestimatedCount: Int {+    Swift.max(0, base.underestimatedCount - 1)+  }+}++/// A collection of adjacent pairs of elements built from an underlying collection.+///+/// In an `AdjacentPairsCollection`, the elements of the *i*th pair are the *i*th+/// and *(i+1)*th elements of the underlying sequence. The following example+/// uses the `adjacentPairs()` method to iterate over adjacent pairs of+/// integers:+/// ```+/// for pair in (1...5).adjacentPairs() {+///     print(pair)+/// }+/// // Prints "(1, 2)"+/// // Prints "(2, 3)"+/// // Prints "(3, 4)"+/// // Prints "(4, 5)"+/// ```+public struct AdjacentPairsCollection<Base: Collection> {+  @usableFromInline+  internal let base: Base++  public let startIndex: Index++  @inlinable+  internal init(base: Base) {+    self.base = base++    // Precompute `startIndex` to ensure O(1) behavior,+    // avoiding indexing past `endIndex`+    let start = base.startIndex+    let end = base.endIndex+    let second = start == end ? start : base.index(after: start)+    self.startIndex = Index(first: start, second: second)+  }+}++extension AdjacentPairsCollection {+  public typealias Iterator = AdjacentPairsSequence<Base>.Iterator++  @inlinable+  public func makeIterator() -> Iterator {+    Iterator(base: base.makeIterator())+  }+}

I'm not sure if this is beneficial, mostly because we're precomputing startIndex. Won't this mean we end up doing some duplicate work when iterating over someCollection.adjacentPairs()?

mpangburn

comment created time in 6 days

Pull request review commentapple/swift-algorithms

Introduce `adjacentPairs`

+//===----------------------------------------------------------------------===//+//+// This source file is part of the Swift Algorithms open source project+//+// Copyright (c) 2021 Apple Inc. and the Swift project authors+// Licensed under Apache License v2.0 with Runtime Library Exception+//+// See https://swift.org/LICENSE.txt for license information+//+//===----------------------------------------------------------------------===//++extension Sequence {+  /// Creates a sequence of adjacent pairs of elements from this sequence.+  ///+  /// In the `AdjacentPairsSequence` returned by this method, the elements of+  /// the *i*th pair are the *i*th and *(i+1)*th elements of the underlying+  /// sequence.+  /// The following example uses the `adjacentPairs()` method to iterate over+  /// adjacent pairs of integers:+  ///+  ///    for pair in (1...5).adjacentPairs() {+  ///        print(pair)+  ///    }+  ///    // Prints "(1, 2)"+  ///    // Prints "(2, 3)"+  ///    // Prints "(3, 4)"+  ///    // Prints "(4, 5)"+  @inlinable+  public func adjacentPairs() -> AdjacentPairsSequence<Self> {+    AdjacentPairsSequence(base: self)+  }+}++extension Collection {+  /// A collection of adjacent pairs of elements built from an underlying collection.+  ///+  /// In an `AdjacentPairsCollection`, the elements of the *i*th pair are the *i*th+  /// and *(i+1)*th elements of the underlying sequence. The following example+  /// uses the `adjacentPairs()` method to iterate over adjacent pairs of+  /// integers:+  /// ```+  /// for pair in (1...5).adjacentPairs() {+  ///     print(pair)+  /// }+  /// // Prints "(1, 2)"+  /// // Prints "(2, 3)"+  /// // Prints "(3, 4)"+  /// // Prints "(4, 5)"+  /// ```+  @inlinable+  public func adjacentPairs() -> AdjacentPairsCollection<Self> {+    AdjacentPairsCollection(base: self)+  }+}++/// A sequence of adjacent pairs of elements built from an underlying sequence.+///+/// In an `AdjacentPairsSequence`, the elements of the *i*th pair are the *i*th+/// and *(i+1)*th elements of the underlying sequence. The following example+/// uses the `adjacentPairs()` method to iterate over adjacent pairs of+/// integers:+/// ```+/// for pair in (1...5).adjacentPairs() {+///     print(pair)+/// }+/// // Prints "(1, 2)"+/// // Prints "(2, 3)"+/// // Prints "(3, 4)"+/// // Prints "(4, 5)"+/// ```+public struct AdjacentPairsSequence<Base: Sequence> {+  @usableFromInline+  internal let base: Base++  /// Creates an instance that makes pairs of adjacent elements from `base`.+  @inlinable+  internal init(base: Base) {+    self.base = base+  }+}++extension AdjacentPairsSequence {+  public struct Iterator {+    @usableFromInline+    internal var base: Base.Iterator++    @usableFromInline+    internal var previousElement: Base.Element?++    @inlinable+    internal init(base: Base.Iterator) {+      self.base = base+    }+  }+}++extension AdjacentPairsSequence.Iterator: IteratorProtocol {+  public typealias Element = (Base.Element, Base.Element)++  @inlinable+  public mutating func next() -> Element? {+    if previousElement == nil {+      previousElement = base.next()+    }++    guard let previous = previousElement, let next = base.next() else {+      return nil+    }++    previousElement = next+    return (previous, next)+  }+}++extension AdjacentPairsSequence: Sequence {+  @inlinable+  public func makeIterator() -> Iterator {+    Iterator(base: base.makeIterator())+  }++  @inlinable+  public var underestimatedCount: Int {+    Swift.max(0, base.underestimatedCount - 1)+  }+}++/// A collection of adjacent pairs of elements built from an underlying collection.+///+/// In an `AdjacentPairsCollection`, the elements of the *i*th pair are the *i*th+/// and *(i+1)*th elements of the underlying sequence. The following example+/// uses the `adjacentPairs()` method to iterate over adjacent pairs of+/// integers:+/// ```+/// for pair in (1...5).adjacentPairs() {+///     print(pair)+/// }+/// // Prints "(1, 2)"+/// // Prints "(2, 3)"+/// // Prints "(3, 4)"+/// // Prints "(4, 5)"+/// ```+public struct AdjacentPairsCollection<Base: Collection> {+  @usableFromInline+  internal let base: Base++  public let startIndex: Index++  @inlinable+  internal init(base: Base) {+    self.base = base++    // Precompute `startIndex` to ensure O(1) behavior,+    // avoiding indexing past `endIndex`+    let start = base.startIndex+    let end = base.endIndex+    let second = start == end ? start : base.index(after: start)+    self.startIndex = Index(first: start, second: second)+  }+}++extension AdjacentPairsCollection {+  public typealias Iterator = AdjacentPairsSequence<Base>.Iterator++  @inlinable+  public func makeIterator() -> Iterator {+    Iterator(base: base.makeIterator())+  }+}++extension AdjacentPairsCollection {+  public struct Index: Comparable {+    @usableFromInline+    internal var first: Base.Index+    +    @usableFromInline+    internal var second: Base.Index++    @inlinable+    internal init(first: Base.Index, second: Base.Index) {+      self.first = first+      self.second = second+    }++    @inlinable+    public static func < (lhs: Index, rhs: Index) -> Bool {+      (lhs.first, lhs.second) < (rhs.first, rhs.second)+    }+  }+}++extension AdjacentPairsCollection: Collection {+  @inlinable+  public var endIndex: Index {+    switch base.endIndex {+    case startIndex.first, startIndex.second:+      return startIndex+    case let end:+      return Index(first: end, second: end)+    }+  }++  @inlinable+  public subscript(position: Index) -> (Base.Element, Base.Element) {+    (base[position.first], base[position.second])+  }++  @inlinable+  public func index(after i: Index) -> Index {+    let next = base.index(after: i.second)+    return next == base.endIndex+      ? endIndex+      : Index(first: i.second, second: next)+  }++  @inlinable+  public func index(_ i: Index, offsetBy distance: Int) -> Index {

AdjacentPairsCollection will also need to implement index(_:offsetBy:limitedBy:) to properly fulfill the RandomAccessCollection requirements — the added complexity of a limit could make this quite tricky though, so absolutely feel free to leave it as a TODO or ask for guidance if it's significantly harder than the version without a limit 🙂

adjacentPairs() also is conceptually similar to windows(ofCount:) and chunks(ofCount:), so their Collection conformances could be useful to draw inspiration from.

mpangburn

comment created time in 6 days

Pull request review commentapple/swift-algorithms

Introduce `adjacentPairs`

+//===----------------------------------------------------------------------===//+//+// This source file is part of the Swift Algorithms open source project+//+// Copyright (c) 2021 Apple Inc. and the Swift project authors+// Licensed under Apache License v2.0 with Runtime Library Exception+//+// See https://swift.org/LICENSE.txt for license information+//+//===----------------------------------------------------------------------===//++extension Sequence {+  /// Creates a sequence of adjacent pairs of elements from this sequence.+  ///+  /// In the `AdjacentPairsSequence` returned by this method, the elements of+  /// the *i*th pair are the *i*th and *(i+1)*th elements of the underlying+  /// sequence.+  /// The following example uses the `adjacentPairs()` method to iterate over+  /// adjacent pairs of integers:+  ///+  ///    for pair in (1...5).adjacentPairs() {+  ///        print(pair)+  ///    }+  ///    // Prints "(1, 2)"+  ///    // Prints "(2, 3)"+  ///    // Prints "(3, 4)"+  ///    // Prints "(4, 5)"+  @inlinable+  public func adjacentPairs() -> AdjacentPairsSequence<Self> {+    AdjacentPairsSequence(base: self)+  }+}++extension Collection {+  /// A collection of adjacent pairs of elements built from an underlying collection.+  ///+  /// In an `AdjacentPairsCollection`, the elements of the *i*th pair are the *i*th+  /// and *(i+1)*th elements of the underlying sequence. The following example+  /// uses the `adjacentPairs()` method to iterate over adjacent pairs of+  /// integers:+  /// ```+  /// for pair in (1...5).adjacentPairs() {+  ///     print(pair)+  /// }+  /// // Prints "(1, 2)"+  /// // Prints "(2, 3)"+  /// // Prints "(3, 4)"+  /// // Prints "(4, 5)"+  /// ```+  @inlinable+  public func adjacentPairs() -> AdjacentPairsCollection<Self> {+    AdjacentPairsCollection(base: self)+  }+}++/// A sequence of adjacent pairs of elements built from an underlying sequence.+///+/// In an `AdjacentPairsSequence`, the elements of the *i*th pair are the *i*th+/// and *(i+1)*th elements of the underlying sequence. The following example+/// uses the `adjacentPairs()` method to iterate over adjacent pairs of+/// integers:+/// ```+/// for pair in (1...5).adjacentPairs() {+///     print(pair)+/// }+/// // Prints "(1, 2)"+/// // Prints "(2, 3)"+/// // Prints "(3, 4)"+/// // Prints "(4, 5)"+/// ```+public struct AdjacentPairsSequence<Base: Sequence> {+  @usableFromInline+  internal let base: Base++  /// Creates an instance that makes pairs of adjacent elements from `base`.+  @inlinable+  internal init(base: Base) {+    self.base = base+  }+}++extension AdjacentPairsSequence {+  public struct Iterator {+    @usableFromInline+    internal var base: Base.Iterator++    @usableFromInline+    internal var previousElement: Base.Element?++    @inlinable+    internal init(base: Base.Iterator) {+      self.base = base+    }+  }+}++extension AdjacentPairsSequence.Iterator: IteratorProtocol {+  public typealias Element = (Base.Element, Base.Element)++  @inlinable+  public mutating func next() -> Element? {+    if previousElement == nil {+      previousElement = base.next()+    }++    guard let previous = previousElement, let next = base.next() else {+      return nil+    }++    previousElement = next+    return (previous, next)+  }+}++extension AdjacentPairsSequence: Sequence {+  @inlinable+  public func makeIterator() -> Iterator {+    Iterator(base: base.makeIterator())+  }++  @inlinable+  public var underestimatedCount: Int {+    Swift.max(0, base.underestimatedCount - 1)+  }+}++/// A collection of adjacent pairs of elements built from an underlying collection.+///+/// In an `AdjacentPairsCollection`, the elements of the *i*th pair are the *i*th+/// and *(i+1)*th elements of the underlying sequence. The following example+/// uses the `adjacentPairs()` method to iterate over adjacent pairs of+/// integers:+/// ```+/// for pair in (1...5).adjacentPairs() {+///     print(pair)+/// }+/// // Prints "(1, 2)"+/// // Prints "(2, 3)"+/// // Prints "(3, 4)"+/// // Prints "(4, 5)"+/// ```+public struct AdjacentPairsCollection<Base: Collection> {+  @usableFromInline+  internal let base: Base++  public let startIndex: Index++  @inlinable+  internal init(base: Base) {+    self.base = base++    // Precompute `startIndex` to ensure O(1) behavior,+    // avoiding indexing past `endIndex`+    let start = base.startIndex+    let end = base.endIndex+    let second = start == end ? start : base.index(after: start)+    self.startIndex = Index(first: start, second: second)+  }+}++extension AdjacentPairsCollection {+  public typealias Iterator = AdjacentPairsSequence<Base>.Iterator++  @inlinable+  public func makeIterator() -> Iterator {+    Iterator(base: base.makeIterator())+  }+}++extension AdjacentPairsCollection {+  public struct Index: Comparable {+    @usableFromInline+    internal var first: Base.Index+    +    @usableFromInline+    internal var second: Base.Index++    @inlinable+    internal init(first: Base.Index, second: Base.Index) {+      self.first = first+      self.second = second+    }++    @inlinable+    public static func < (lhs: Index, rhs: Index) -> Bool {+      (lhs.first, lhs.second) < (rhs.first, rhs.second)+    }+  }+}++extension AdjacentPairsCollection: Collection {+  @inlinable+  public var endIndex: Index {+    switch base.endIndex {+    case startIndex.first, startIndex.second:+      return startIndex+    case let end:+      return Index(first: end, second: end)+    }+  }

I strongly suggest unconditionally representing endIndex as Index(first: base.endIndex, second: base.endIndex), and adapting startIndex to match this representation in the edge case that base.count == 1 (instead of the other way around). This is the approach we take in Windows as well. Having a consistent representation of endIndex often makes it easier to reason about index manipulation logic, and I think you'll find that it will improve some of your code.

mpangburn

comment created time in 12 hours

issue commentspotify/XCMetrics

Web interface

It would be great to have a list of html pages, that XCLogParser parser with html report creates with links to it.

I guess that's the next destination of current public release, without any additional analytics over a bunch of builds. Probably we need a fork now :)

bolismauro

comment created time in 12 hours

Pull request review commentapple/swift-algorithms

Add new heading and description for partitionIndex 🤷‍♂️.

 Read more about the package, and the intent behind it, in the [announcement on s - [`split(maxSplits:omittingEmptySubsequences:whereSeparator)`, `split(separator:maxSplits:omittingEmptySubsequences)`](https://github.com/apple/swift-algorithms/blob/main/Guides/LazySplit.md): Lazy versions of the Standard Library's eager operations that split sequences and collections into subsequences separated by the specified separator element. - [`windows(ofCount:)`](https://github.com/apple/swift-algorithms/blob/main/Guides/Windows.md): Breaks a collection into overlapping subsequences where elements are slices from the original collection. +#### Binary Search Partitions

Thanks for the feedback @xwu! I was following issue #131 " It needs to be in a different category, though."

LemonSpike

comment created time in 13 hours

Pull request review commentapple/swift-algorithms

PR template Contribution Guidelines link doesn't work

      If this pull request adds new API, please add '?template=new.md'     to the URL to switch to the appropriate template.-+    

LemonSpike

comment created time in 13 hours

Pull request review commentapple/swift-algorithms

Add new heading and description for partitionIndex 🤷‍♂️.

 Read more about the package, and the intent behind it, in the [announcement on s - [`split(maxSplits:omittingEmptySubsequences:whereSeparator)`, `split(separator:maxSplits:omittingEmptySubsequences)`](https://github.com/apple/swift-algorithms/blob/main/Guides/LazySplit.md): Lazy versions of the Standard Library's eager operations that split sequences and collections into subsequences separated by the specified separator element. - [`windows(ofCount:)`](https://github.com/apple/swift-algorithms/blob/main/Guides/Windows.md): Breaks a collection into overlapping subsequences where elements are slices from the original collection. +#### Binary Search Partitions

If this deserves its own heading, then it should follow the same capitalization and grammatical phrasing as other headings, and it should be above "Other useful operations"; otherwise, it should be added to the latter section in alphabetical order.

LemonSpike

comment created time in 13 hours

startedapptekstudios/ASCollectionView

started time in 14 hours

issue commentspotify/XCLogParser

Swift Type check times stopped reporting

Same problem here :(

ChristopherDrum

comment created time in 16 hours