diff --git a/Sources/FoundationPlus/Extensions/Swift/Array.swift b/Sources/FoundationPlus/Extensions/Swift/Array.swift index 7f513b2..216af0f 100644 --- a/Sources/FoundationPlus/Extensions/Swift/Array.swift +++ b/Sources/FoundationPlus/Extensions/Swift/Array.swift @@ -101,10 +101,16 @@ public extension Array where Element: Equatable { Appends elements of an array to the array uniquely. - parameter newElements: The new elements to add + - parameter condition: The condition to filter new unique elements with. */ - @inlinable mutating func appendUniquely(contentsOf newElements: S) where Element == S.Element, S: Sequence { + @inlinable mutating func appendUniquely( + contentsOf newElements: S, + where condition: (S.Element) -> Bool = { _ in true } + ) where Element == S.Element, S: Sequence { for element in newElements { - self.appendUniquely(element) + if condition(element) { + self.appendUniquely(element) + } } } diff --git a/Sources/FoundationPlus/Extensions/Swift/String.swift b/Sources/FoundationPlus/Extensions/Swift/String.swift index 83e6564..cc534cb 100644 --- a/Sources/FoundationPlus/Extensions/Swift/String.swift +++ b/Sources/FoundationPlus/Extensions/Swift/String.swift @@ -21,6 +21,11 @@ public extension String { return components(separatedBy: " ").first ?? "" } + /// The first word in the string. + var lastWord: String { + return components(separatedBy: " ").last ?? "" + } + // MARK: - Static Methods /**