Skip to content

[NFC] Using precondition instead of assert in calls that do not allow negative values #61

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sources/Algorithms/Combinations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ extension Collection {
/// accesses the `count` of the base collection.
@inlinable
public func combinations(ofCount k: Int) -> Combinations<Self> {
assert(k >= 0, "Can't have combinations with a negative number of elements.")
precondition(k >= 0, "Can't have combinations with a negative number of elements.")
return Combinations(self, k: k)
}
}
2 changes: 1 addition & 1 deletion Sources/Algorithms/Permutations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ extension Collection {
///
/// - Complexity: O(1)
public func permutations(ofCount k: Int? = nil) -> Permutations<Self> {
assert(
precondition(
k ?? 0 >= 0,
"Can't have permutations with a negative number of elements.")
return Permutations(self, k: k)
Expand Down