This library provides an extension to the family of Collection protocols (Collection, MutableCollection, and RangeReplacableCollection) for easier and range-safe access to its elements. Most of the added functions return optionals where .none is returned instead of conventional fatal error.
func element(at index: Index) -> Element?func indexInBounds(_ index: Index) -> Bool
mutating func removeLastSafe() -> SubSequence.Element?mutating func removeFirstSafe() -> SubSequence.Element?mutating func replaceOccurrences(with element: Element, where predicate: (Element) -> Bool)mutating func removeElement(where predicate: (Element) -> Bool) -> Self.Element?
mutating func replaceOccurrences(of element: Element, with newElement: Element)mutating func removeElement(element: Element) -> Self.Element?mutating func removeElement(at index: Self.Index) -> Self.Element?mutating func removeDuplicates()
The functions return a new collection
func removingLast() -> Selffunc removingFirst() -> Selffunc removingElement(where predicate: (Element) -> Bool) -> Selffunc replacingOccurrences(with newElement: Element, where predicate: (Element) -> Bool) -> Selffunc replacing(with newElement: Element, at index: Self.Index) -> Selffunc removing(at index: Self.Index) -> Self
func removingElement(_ element: Element) -> Selffunc replacingOccurrences(of element: Element, with newElement: Element ) -> Selffunc removingDuplicates() -> Self
To run the example project, clone the repo, and run pod install from the Example directory first.
SwiftyCollection is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'SwiftyCollection'Swift-Gurus Inc., alexei.hmelevski@gmail.com
SwiftyCollection is available under the MIT license. See the LICENSE file for more info.