Skip to content

Conversation

natecook1000
Copy link
Member

@natecook1000
Copy link
Member Author

@swift-ci Please smoke test

/// the element should be included in the count.
/// - Returns: The number of elements in the sequence that satisfy the given
/// predicate.
@inlinable
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need availability? Could we make this @backDeployed?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The standard library can't effectively use @backDeploy yet as there are, issues... I would however throw an @_alwaysEmitIntoClient on.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should reduce and/or typed throws be used?

extension Sequence {
  @_alwaysEmitIntoClient
  public func count<Failure: Error>(
    where predicate: (Element) throws(Failure) -> Bool
  ) throws(Failure) -> Int {
    try reduce(into: 0) { result, element in
      if try predicate(element) {
        result += 1
      }
    }
  }
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@benrimmington We're handling the addition of typed throws throughout the standard library separately. The loop is fine here.

@natecook1000
Copy link
Member Author

@swift-ci Please smoke test

@natecook1000
Copy link
Member Author

@swift-ci Please smoke test Linux platform

@xwu
Copy link
Collaborator

xwu commented Jan 22, 2024

@swift-ci please smoke test

@benrimmington

This comment was marked as outdated.

@natecook1000
Copy link
Member Author

@swift-ci Please smoke test

@natecook1000
Copy link
Member Author

@swift-ci Please test

@natecook1000 natecook1000 marked this pull request as ready for review March 27, 2024 13:01
@natecook1000 natecook1000 requested review from a team, hborla and xedin as code owners March 27, 2024 13:01
/// the element should be included in the count.
/// - Returns: The number of elements in the sequence that satisfy the given
/// predicate.
@_alwaysEmitIntoClient
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this not need the ABI shims since it is AEIC?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is brand-new API for the standard library, and it needs to be AEIC due to typed throws, so there's no existing ABI to worry about 👍🏻

@natecook1000 natecook1000 merged commit 38e1370 into main Mar 29, 2024
@natecook1000 natecook1000 deleted the revert-revert-count-where branch March 29, 2024 18:53
natecook1000 added a commit that referenced this pull request Mar 29, 2024
* Revert "Revert count(where:)"

This reverts commit 779ea19.

Now that SE-0220 has been re-accepted, this adds the `count(where:)` 
Sequence method to the standard library.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants