Swiftpack.co - Swift-Gurus/SwiftyCollection as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by Swift-Gurus.
Swift-Gurus/SwiftyCollection 2.0.0
Safe operations on collections
⭐️ 1
🕓 3 years ago
.package(url: "https://github.com/Swift-Gurus/SwiftyCollection.git", from: "2.0.0")

SwiftyCollection

Build Status Version License Platform

Desription

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.

Collection Methods

  • func element(at index: Index) -> Element?
  • func indexInBounds(_ index: Index) -> Bool

Mutable RangeReplaceableCollection Collection Methods

  • 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?

Mutable RangeReplaceableCollection Collection Methods with Equatable 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()

RangeReplaceableCollection

The functions return a new collection

  • func removingLast() -> Self
  • func removingFirst() -> Self
  • func removingElement(where predicate: (Element) -> Bool) -> Self
  • func replacingOccurrences(with newElement: Element, where predicate: (Element) -> Bool) -> Self
  • func replacing(with newElement: Element, at index: Self.Index) -> Self
  • func removing(at index: Self.Index) -> Self

RangeReplaceableCollection with Equatable Element

  • func removingElement(_ element: Element) -> Self
  • func replacingOccurrences(of element: Element, with newElement: Element ) -> Self
  • func removingDuplicates() -> Self

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Installation

SwiftyCollection is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'SwiftyCollection'

Author

Swift-Gurus Inc., [email protected]

License

SwiftyCollection is available under the MIT license. See the LICENSE file for more info.

GitHub

link
Stars: 1
Last commit: 3 years ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

Warning Fixes
4 years ago

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics