Skip to content

Instantly share code, notes, and snippets.

@czars
Created September 24, 2019 08:36
Show Gist options
  • Select an option

  • Save czars/79f6a8e26fc905fc14f1c28e12e6c416 to your computer and use it in GitHub Desktop.

Select an option

Save czars/79f6a8e26fc905fc14f1c28e12e6c416 to your computer and use it in GitHub Desktop.

Revisions

  1. czars created this gist Sep 24, 2019.
    7 changes: 7 additions & 0 deletions chunk swift array
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    extension Array {
    func chunked(into size: Int) -> [[Element]] {
    return stride(from: 0, to: count, by: size).map {
    Array(self[$0 ..< Swift.min($0 + size, count)])
    }
    }
    }