module Development.Shake.Plus.Loaders (
loadSortFilterApply
, loadSortFilterApplyW
) where
import Development.Shake.Plus.Core
import Development.Shake.Plus.Directory
import RIO
import RIO.List
import Path
import Within
traverseToSnd :: Functor f => (a -> f b) -> a -> f (a, b)
traverseToSnd f a = (a,) <$> f a
loadSortFilterApply :: (MonadAction m, Ord b)
=> (Path Rel File -> m a)
-> Path Rel Dir
-> [FilePattern]
-> (a -> b)
-> (a -> Bool)
-> (a -> a)
-> m [(Path Rel File, a)]
loadSortFilterApply l dir pat s f e = do
xs <- getDirectoryFiles dir pat >>= mapM (traverseToSnd l)
return $ fmap (second e) $ sortOn (s . snd) $ filter (f . snd) $ xs
loadSortFilterApplyW :: (MonadAction m, Ord b)
=> (Within Rel File -> m a)
-> Path Rel Dir
-> [FilePattern]
-> (a -> b)
-> (a -> Bool)
-> (a -> a)
-> m [(Within Rel File, a)]
loadSortFilterApplyW l dir pat s f e = do
xs <- getDirectoryFilesWithin dir pat >>= mapM (traverseToSnd l)
return $ fmap (second e) $ sortOn (s . snd) $ filter (f . snd) $ xs