Skip to content

Commit

Permalink
Timecode.Component: Added first(excluding:) and `last(excluding:)…
Browse files Browse the repository at this point in the history
…` methods
  • Loading branch information
orchetect committed Oct 13, 2024
1 parent adcfbd0 commit 57ded74
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Sources/TimecodeKit/Timecode/Components/Component.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,20 @@ extension Timecode.Component: Sendable { }
// MARK: - Sequence Traversal

extension Timecode.Component {
/// Returns the first timecode component in sequence.
public static func first(excluding: Set<Self> = []) -> Self {
let components = allCases.filter { !excluding.contains($0) }
precondition(!components.isEmpty)
return components.first!
}

/// Returns the last timecode component in sequence.
public static func last(excluding: Set<Self> = []) -> Self {
let components = allCases.filter { !excluding.contains($0) }
precondition(!components.isEmpty)
return components.last!
}

/// Returns the next timecode component in sequence.
/// If the component is the last in the sequence, the sequence wraps around and returns the first component.
public func next(excluding: Set<Self> = []) -> Self {
Expand Down

0 comments on commit 57ded74

Please sign in to comment.