SwiftyCollection 1.0.6

SwiftyCollection 1.0.6

Maintained by Alex Hmelevski, Alex Hmelevski, Piyush Sharma.



  • By
  • ALDO Inc

SwiftyCollection

CircleCI 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

ALDO Inc., [email protected]

License

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