mirror of
https://github.com/yattee/yattee.git
synced 2026-08-26 00:42:33 +00:00
18 lines
364 B
Swift
18 lines
364 B
Swift
//
|
|
// Array+Chunked.swift
|
|
// Yattee
|
|
//
|
|
// Splitting arrays into fixed-size chunks.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
extension Array {
|
|
/// Splits the array into chunks of the specified size.
|
|
func chunked(into size: Int) -> [[Element]] {
|
|
stride(from: 0, to: count, by: size).map {
|
|
Array(self[$0..<Swift.min($0 + size, count)])
|
|
}
|
|
}
|
|
}
|