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.
- Platforms:
- macOS 10.9+
- iOS 8.0+
- watchOS 2.0+
- tvOS 9.0+
- Linux
- Xcode 8.0
- Swift 3.0
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
CocoaPods is a centralized dependency manager for Objective-C and Swift. Go here to learn more.
-
Add the project to your Podfile.
use_frameworks! pod 'OneOrMore', '~> 1.0.0'
If you want to be on the bleeding edge, replace the last line with:
pod 'OneOrMore', :git => 'https://github.com/nvzqz/OneOrMore.git'
-
Run
pod install
and open the.xcworkspace
file to launch Xcode. -
Import the OneOrMore framework.
import OneOrMore
Carthage is a decentralized dependency manager for Objective-C and Swift.
-
Add the project to your Cartfile.
github "nvzqz/OneOrMore"
-
Run
carthage update
and follow the additional steps in order to add OneOrMore to your project. -
Import the OneOrMore framework.
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.