TestsTested | ✗ |
LangLanguage | SwiftSwift |
License | MIT |
ReleasedLast Release | Nov 2016 |
SwiftSwift Version | 3.0 |
SPMSupports SPM | ✓ |
Maintained by Nikolai Vazquez.
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.
The Swift Package Manager is a decentralized dependency manager for Swift.
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)
]
)
Import the OneOrMore module.
import OneOrMore
Simply add the OneOrMore.swift
file into your project.
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]
OneOrMore is published under the MIT License.