Skip to content

Commit

Permalink
fix: allow StationSet to be initialized with an array of stations
Browse files Browse the repository at this point in the history
  • Loading branch information
emma-k-alexandra committed Dec 27, 2021
1 parent ab632a5 commit 130b9a7
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions Sources/WMATA/Rail.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1022,8 +1022,13 @@ public extension Rail {
///
/// Avoid using single stations like ` [.waterfront]`, ``Rail/NextTrains/init(key:station:delegate:)`` is recommended instead. However, single value sets _are_ supported if your use case requires them.
public struct StationSet: ExpressibleByArrayLiteral, Equatable, Hashable {
let stations: [Station]
let all: Bool
/// The stations this set contains.
///
/// This may be empty if ``all`` is `true`.
public let stations: [Station]

/// If this station set contains all stations.
public let all: Bool

/// Use this when you want to get the next trains at all stations in one API call
public static let all: StationSet = .init(all: true)
Expand All @@ -1040,11 +1045,18 @@ public extension Rail {
/// Both Gallery Place platforms
public static let galleryPlace: StationSet = [.galleryPlaceLower, .galleryPlaceUpper]

/// Create a station set from an array literal of stations
public init(arrayLiteral elements: Station...) {
stations = elements
all = false
}

/// Create a station set from an array of stations
public init(_ elements: [Station]) {
stations = elements
all = false
}

init(all: Bool) {
stations = []
self.all = all
Expand Down

0 comments on commit 130b9a7

Please sign in to comment.