From ac7820bdd2fa5dbfe4b0b099f2fd066da9b9de8f Mon Sep 17 00:00:00 2001 From: Igor Kislyuk Date: Thu, 19 Oct 2017 01:24:49 +0300 Subject: [PATCH] Remove array extensions --- CHANGELOG.md | 1 + .../Extensions/Array/Array+Extensions.swift | 46 +------------------ 2 files changed, 3 insertions(+), 44 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e22137dd..3d0f1a62 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ - **Remove**: String+Extensions - **Remove**: UICollectionView+CellRegistration - **Remove**: UIStoryboard+InstantiateViewController +- **Remove**: `Array` extensions with `Set Algebra` ## 0.5.18 - **Fix**: EmptyCell first appearance setup fix diff --git a/Sources/Extensions/Array/Array+Extensions.swift b/Sources/Extensions/Array/Array+Extensions.swift index edd47dfc..1d3d58e9 100644 --- a/Sources/Extensions/Array/Array+Extensions.swift +++ b/Sources/Extensions/Array/Array+Extensions.swift @@ -20,52 +20,10 @@ // THE SOFTWARE. // -public extension Array where Element: Equatable { - - /// Union array with another arrays, without element duplication - func union(values: [Array.Element]...) -> Array { - var result = self - - for array in values { - for value in array { - if !result.contains(value) { - result.append(value) - } - } - } - - return result - } - - /// Find common elements among arrays - func intersection(values: [Array.Element]...) -> Array { - var result = self - var intersection = Array() - - for (index, value) in values.enumerated() { - if index > 0 { - result = intersection - intersection = Array() - } - - value.forEach { item in - if result.contains(item) && !intersection.contains(item) { - intersection.append(item) - } - } - } - - return intersection - } - - /// Find unique elements in array compared to other arrays - func subtract(values: [Array.Element]...) -> Array { - let allValues = values.flatMap { $0 } - return filter { !allValues.contains($0) } - } +public extension Array { // Subscript for safe access to element by index - subscript(safe index: Int) -> Element? { + subscript(safe index: Index) -> Element? { return index < count ? self[index] : nil }