>>> chunksOf 3 [1..12] [[1,2,3],[4,5,6],[7,8,9],[10,11,12]]
>>> chunksOf 3 "Hello there" ["Hel","lo ","the","re"]
>>> chunksOf 3 ([] :: [Int]) []Note that chunksOf n [] is [], not [[]]. This is intentional, and satisfies the property that
chunksOf n xs ++ chunksOf n ys == chunksOf n (xs ++ ys)whenever n evenly divides the length of xs.
>>> removes 2 "abcdef" ["cdef","abef","abcd"]
chunksOf 3 "my test" == ["my ","tes","t"] chunksOf 3 "mytest" == ["myt","est"] chunksOf 8 "" == [] chunksOf 0 "test" == undefined
>>> sliceHorizontal 6 ['a'..'z'] ["agmsy","bhntz","ciou","djpv","ekqw","flrx"]
\(NonEmpty xs) -> QC.forAll (QC.choose (1, length xs)) $ \n -> sliceHorizontal n xs == transpose (sliceVertical n (xs::String))
\(NonEmpty xs) -> QC.forAll (QC.choose (1, length xs)) $ \n -> sliceVertical n xs == transpose (sliceHorizontal n (xs::String))The properties do not hold for empty lists because of:
>>> sliceHorizontal 4 ([]::[Int]) [[],[],[],[]]
>>> sliceVertical 6 ['a'..'z'] ["abcdef","ghijkl","mnopqr","stuvwx","yz"]
>>> chunksOf 5 (take 30 $ repeat 'a') ["aaaaa","aaaaa","aaaaa","aaaaa","aaaaa","aaaaa"]
>>> listChunksOf 3 [0..7] [[0,1,2],[3,4,5],[6,7]] >>> listChunksOf 0 [0..10] [] >>> listChunksOf (-13) [0..10] [] >>> listChunksOf 100 [1,2,3] [[1,2,3]]
>>> P.take 2 $ listChunksOf 3 [1..] [[1,2,3],[4,5,6]]
chunksOf n xs ++ chunksOf n ys == chunksOf n (xs ++ ys)whenever n evenly divides the length of xs.
replicateM n (pure x) == replicate n x
>>> replicateM 3 getLine hi heya hiya ["hi","heya","hiya"]
>>> import Control.Monad.State >>> runState (replicateM 3 $ state $ \s -> (s, s + 1)) 1 ([1,2,3],4)
>>> import Control.Monad.State >>> runState (replicateM 3 $ state $ \s -> (s, s + 1)) 1 ([1,2,3],4)
do a1 <- as a2 <- as a3 <- as a4 <- as a5 <- as pure [a1,a2,a3,a4,a5]Note the Applicative constraint.