module Test.Speculate.Utils.Tiers
( productsList
, mapTMaybe
, uptoT
, filterTS
, discardTS
)
where
import Test.LeanCheck
import Data.Maybe (mapMaybe)
productsList :: [[a]] -> [[a]]
productsList = concat . products . map toTiers
mapTMaybe :: (a -> Maybe b) -> [[a]] -> [[b]]
mapTMaybe f = map (mapMaybe f)
uptoT :: Int -> [[a]] -> [a]
uptoT sz = concat . take sz
filterTS :: (Int -> a -> Bool) -> [[a]] -> [[a]]
filterTS p = fts 0
where
fts n [] = []
fts n (xs:xss) = filter (p n) xs : fts (n+1) xss
discardTS :: (Int -> a -> Bool) -> [[a]] -> [[a]]
discardTS p = filterTS ((not .) . p)