CocoaPods trunk is moving to be read-only. Read more on the blog, there are 18 months to go.

OneOrMore 1.4.0

OneOrMore 1.4.0

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Nov 2016
SwiftSwift Version 3.0
SPMSupports SPM

Maintained by Nikolai Vazquez.



OneOrMore 1.4.0

OneOrMore

A Swift collection of one or more elements.

A OneOrMore instance must have one or more elements. This makes it great for tasks such as implementing an undo history. Chris Eidhof outlines a great example here.

Installation

Compatibility

  • Platforms:
    • macOS 10.9+
    • iOS 8.0+
    • watchOS 2.0+
    • tvOS 9.0+
    • Linux

  • Xcode 7.3 and 8.0 beta 4
  • Swift 2.2 and 3.0 preview 4

Install Using Swift Package Manager

The Swift Package Manager is a decentralized dependency manager for Swift.

  1. Add the project to your Package.swift.

    import PackageDescription
    
    let package = Package(
        name: "MyAwesomeProject",
        dependencies: [
            .Package(url: "https://github.com/nvzqz/OneOrMore.git",
                     majorVersion: 1)
        ]
    )
  2. Import the OneOrMore module.

    import OneOrMore

Install Manually

Simply add the OneOrMore.swift file into your project.

Usage

let numbers = OneOrMore(1, 2, 3)

Because a OneOrMore instance is guaranteed to have one or more elements, properties such as first and last return a non-optional value.

OneOrMore has overloaded map(_:), sorted(by:), and reversed() methods that return OneOrMore.

let multiplesOfTwo = numbers.map { $0 * 2 }  // OneOrMore<Int> [2, 4, 6]

let reversed = values.reversed()  // OneOrMore<Int> [6, 4, 2]

let sorted = reversed.sorted(by: <)  // OneOrMore<Int> [2, 4, 6]

License

OneOrMore is published under the MIT License.