2024-12-25 18:06:05 +01:00

14 lines
309 B
Swift

extension Array {
func split(into size: Int) -> [[Element]] {
guard size > 0 else { return [] }
return stride(from: 0, to: count, by: size).map {
Array(self[$0..<Swift.min($0 + size, count)])
}
}
var nonEmpty: Self? {
isEmpty ? nil : self
}
}