Skip to content

Files

Latest commit

 

History

History
35 lines (18 loc) · 783 Bytes

is_disjoint.md

File metadata and controls

35 lines (18 loc) · 783 Bytes

Pattern: Use of Set.intersection(_:).isEmpty

Issue: -

Description

Prefer using Set.isDisjoint(with:) over Set.intersection(_:).isEmpty.

Examples of correct code:

_ = Set(syntaxKinds).isDisjoint(with: commentAndStringKindsSet)


let isObjc = !objcAttributes.isDisjoint(with: dictionary.enclosedSwiftAttributes)


_ = Set(syntaxKinds).intersection(commentAndStringKindsSet)


_ = !objcAttributes.intersection(dictionary.enclosedSwiftAttributes)

Examples of incorrect code:

_ = Set(syntaxKinds).intersection(commentAndStringKindsSet).isEmpty


let isObjc = !objcAttributes.intersection(dictionary.enclosedSwiftAttributes).isEmpty

Further Reading