diff --git a/Sources/Bond/Data Sources/SectionedDataSourceChangesetConvertible.swift b/Sources/Bond/Data Sources/SectionedDataSourceChangesetConvertible.swift index 7cd7b158..874c5ea2 100644 --- a/Sources/Bond/Data Sources/SectionedDataSourceChangesetConvertible.swift +++ b/Sources/Bond/Data Sources/SectionedDataSourceChangesetConvertible.swift @@ -75,6 +75,12 @@ extension Array: SectionedDataSourceChangesetConvertible { } } +extension Array2D: SectionedDataSourceChangesetConvertible { + public var asSectionedDataSourceChangeset: OrderedCollectionChangeset { + return OrderedCollectionChangeset(collection: self, patch: []) + } +} + extension OrderedCollectionChangeset: SectionedDataSourceChangeset where Diff.Index: SectionedDataIndexPathConvertable, Collection: SectionedDataSourceProtocol {} extension OrderedCollectionChangeset: SectionedDataSourceChangesetConvertible where Diff.Index: SectionedDataIndexPathConvertable, Collection: SectionedDataSourceProtocol { diff --git a/Sources/Bond/Data Structures/Array2D.swift b/Sources/Bond/Data Structures/Array2D.swift index 0d591ff0..b4e0809a 100644 --- a/Sources/Bond/Data Structures/Array2D.swift +++ b/Sources/Bond/Data Structures/Array2D.swift @@ -219,3 +219,37 @@ extension Array2D { } } } + +// MARK: - Sequence conformance + +extension Array2D: Swift.Sequence { + public typealias Iterator = IndexingIterator<[Array2D.Section]> + + public func makeIterator() -> Iterator { + return sections.makeIterator() + } +} + +// MARK: - Collection conformance + +extension Array2D: Collection { + public typealias Index = Int + + public var startIndex: Index { + return sections.startIndex + } + + public var endIndex: Index { + return sections.endIndex + } + + public subscript(position: Index) -> Iterator.Element { + precondition(indices.contains(position), "out of bounds") + let element = sections[position] + return element + } + + public func index(after i: Index) -> Index { + return sections.index(after: i) + } +}