Skip to content

Commit

Permalink
⚡️ Append under conditions; last word
Browse files Browse the repository at this point in the history
  • Loading branch information
benlmyers committed Oct 25, 2022
1 parent 520ca2d commit 449a8b9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
10 changes: 8 additions & 2 deletions Sources/FoundationPlus/Extensions/Swift/Array.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<S>(contentsOf newElements: S) where Element == S.Element, S: Sequence {
@inlinable mutating func appendUniquely<S>(
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)
}
}
}

Expand Down
5 changes: 5 additions & 0 deletions Sources/FoundationPlus/Extensions/Swift/String.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand Down

0 comments on commit 449a8b9

Please sign in to comment.