Skip to content

Commit

Permalink
IndexSet apply mutation
Browse files Browse the repository at this point in the history
  • Loading branch information
mattmassicotte committed Jan 18, 2024
1 parent 9f5f8da commit 89b4b84
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions Sources/Rearrange/IndexSet+ApplyMutation.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import Foundation

extension IndexSet {
public func apply(mutation: RangeMutation) -> IndexSet {
let ranges = nsRangeView.compactMap { $0.apply(mutation) }

return IndexSet(ranges: ranges)
}

public mutating func applying(mutation: RangeMutation) {
self = self.apply(mutation: mutation)
}

public func apply(mutations: [RangeMutation]) -> IndexSet {
var ranges = nsRangeView

for mutation in mutations {
ranges = ranges.compactMap { $0.apply(mutation) }
}

return IndexSet(ranges: ranges)
}

public mutating func applying(mutations: [RangeMutation]) {
self = self.apply(mutations: mutations)
}
}

0 comments on commit 89b4b84

Please sign in to comment.