Skip to content

Latest commit

 

History

History
18 lines (16 loc) · 388 Bytes

chunk-array.md

File metadata and controls

18 lines (16 loc) · 388 Bytes
title description author tags
Chunk Array
Splits an array into chunks of a specified size.
ACR1209
array,chunk,utility
chunkArray :: Int -> [a] -> [[a]]
chunkArray _ [] = []
chunkArray n xs = take n xs : chunkArray n (drop n xs)

-- Usage:
main :: IO ()
main = do
    let array = [1, 2, 3, 4, 5, 6]
    print $ chunkArray 2 array -- Output: [[1, 2], [3, 4], [5, 6]]