>>> 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"]
>>> Comb.variateRep 2 "abc" ["aa","ab","ac","ba","bb","bc","ca","cb","cc"]
>>> Comb.variate 2 "abc" ["ab","ac","ba","bc","ca","cb"] >>> Comb.variate 2 "abcd" ["ab","ac","ad","ba","bc","bd","ca","cb","cd","da","db","dc"] >>> Comb.variate 3 "abcd" ["abc","abd","acb","acd","adb","adc","bac","bad","bca","bcd","bda","bdc","cab","cad","cba","cbd","cda","cdb","dab","dac","dba","dbc","dca","dcb"]
QC.forAll genVariate $ \xs -> Comb.variate (length xs) xs == Comb.permute xs
\xs -> equating (take 1000) (Comb.variate (length xs) xs) (Comb.permute (xs::String))
>>> Comb.tuples 2 "abc" ["ab","ac","bc"] >>> Comb.tuples 2 "abcd" ["ab","ac","ad","bc","bd","cd"] >>> Comb.tuples 3 "abcd" ["abc","abd","acd","bcd"]
>>> Comb.rectifications 4 "abc" ["aabc","abac","abbc","abca","abcb","abcc"] >>> map (length . uncurry Comb.rectifications) $ do x<-[0..10]; y<-[0..x]; return (x,[1..y::Int]) [1,0,1,0,1,1,0,1,3,1,0,1,7,6,1,0,1,15,25,10,1,0,1,31,90,65,15,1,0,1,63,301,350,140,21,1,0,1,127,966,1701,1050,266,28,1,0,1,255,3025,7770,6951,2646,462,36,1,0,1,511,9330,34105,42525,22827,5880,750,45,1]
QC.forAll (QC.choose (0,7)) $ \k xs -> isAscending . Comb.rectifications k . nub . sort $ (xs::String)
>>> 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)