mirror of
https://github.com/stoatchat/for-ios.git
synced 2026-07-18 16:04:32 -04:00
37 lines
748 B
Swift
37 lines
748 B
Swift
//
|
|
// IteratorProtocol.swift
|
|
// Revolt
|
|
//
|
|
// Created by Angelo on 19/06/2024.
|
|
//
|
|
|
|
extension IteratorProtocol {
|
|
mutating func next(n: Int) -> [Self.Element] {
|
|
var values: [Self.Element] = []
|
|
|
|
for _ in 0...n {
|
|
if let v = self.next() {
|
|
values.append(v)
|
|
}
|
|
}
|
|
|
|
return values
|
|
}
|
|
|
|
mutating func groups(n: Int) -> [[Self.Element]] {
|
|
var values: [[Self.Element]] = []
|
|
|
|
while true {
|
|
let group = self.next(n: n)
|
|
|
|
if group.count > 0 {
|
|
values.append(group)
|
|
}
|
|
|
|
if group.count != n {
|
|
return values
|
|
}
|
|
}
|
|
}
|
|
}
|