Copyright | (c) Christian Gram Kalhauge 2019 |
---|---|
License | MIT |
Maintainer | kalhauge@cs.ucla.edu |
Safe Haskell | None |
Language | Haskell2010 |
A directory tree, with helper functions to do different cool stuff.
Synopsis
- newtype DirTree s a = DirTree {
- dirTreeNode :: DirTreeN s a
- file :: a -> DirTree s a
- symlink :: s -> DirTree s a
- directory :: FileMap (DirTree s a) -> DirTree s a
- directoryFromFiles :: [(String, DirTree s a)] -> DirTree s a
- fromFiles :: [(FileKey, Either v a)] -> Maybe (DirTree v a)
- fromFiles' :: NonEmpty (FileKey, Either v a) -> DirTree v a
- fromFile :: FileKey -> a -> DirTree Void a
- toFiles :: DirTree v a -> [(FileKey, Either v a)]
- type FileKey = [String]
- fileKeyToPath :: FileKey -> FilePath
- fileKeyFromPath :: FilePath -> FileKey
- lookupFile :: FileKey -> DirTree v a -> Maybe (DirTree v a)
- traverseDirTree :: Applicative f => (DirTreeNode (FileMap (f (DirTree s' a'))) s a -> f (DirTreeN s' a')) -> DirTree s a -> f (DirTree s' a')
- traverseDirTree' :: Applicative m => (s -> m s') -> (a -> m a') -> DirTree s a -> m (DirTree s' a')
- itraverseDirTree :: Applicative f => (FileKey -> DirTreeNode (FileMap (f (DirTree s' a'))) s a -> f (DirTreeN s' a')) -> DirTree s a -> f (DirTree s' a')
- itraverseDirTree' :: Applicative f => (FileKey -> s -> f s') -> (FileKey -> a -> f a') -> DirTree s a -> f (DirTree s' a')
- mapDirTree' :: (s -> s') -> (a -> a') -> DirTree s a -> DirTree s' a'
- imapDirTree' :: (FileKey -> s -> s') -> (FileKey -> a -> a') -> DirTree s a -> DirTree s' a'
- depthfirst :: Monoid m => (FileKey -> DirTreeNode [String] v a -> m) -> DirTree v a -> m
- foldDirTree :: (DirTreeNode (FileMap m) s a -> m) -> DirTree s a -> m
- foldDirTree' :: Monoid m => (s -> m) -> (a -> m) -> DirTree s a -> m
- ifoldDirTree :: (FileKey -> DirTreeNode (FileMap m) s a -> m) -> DirTree s a -> m
- ifoldDirTree' :: Monoid m => (FileKey -> s -> m) -> (FileKey -> a -> m) -> DirTree s a -> m
- flatten :: (s -> DirTree s' a') -> (a -> DirTree s' a') -> DirTree s a -> DirTree s' a'
- findNode :: (FileKey -> DirTreeNode [String] v a -> Bool) -> DirTree v a -> Maybe (FileKey, DirTreeNode [String] v a)
- listNodes :: DirTree v a -> [(FileKey, DirTreeNode [String] v a)]
- readDirTree :: NFData a => (FilePath -> IO a) -> FilePath -> IO (DirTree Link a)
- lazyReadDirTree :: (FilePath -> IO a) -> FilePath -> IO (DirTree Link a)
- writeDirTree :: (FilePath -> a -> IO ()) -> FilePath -> DirTree Link a -> IO ()
- followLinks :: NFData a => (FilePath -> IO a) -> DirTree Link a -> IO (DirTree Void a)
- lazyFollowLinks :: (FilePath -> IO a) -> DirTree Link a -> IO (DirTree Void a)
- data Link
- data DirTreeNode r s a
- type FileType = DirTreeNode () () ()
- fileTypeOfNode :: DirTreeNode a b c -> FileType
- mapDirTreeNode :: (r -> r') -> (s -> s') -> (a -> a') -> DirTreeNode r s a -> DirTreeNode r' s' a'
- foldDirTreeNode :: (r -> m) -> (s -> m) -> (a -> m) -> DirTreeNode r s a -> m
- traverseDirTreeNode :: Functor m => (r -> m r') -> (s -> m s') -> (a -> m a') -> DirTreeNode r s a -> m (DirTreeNode r' s' a')
- getFileType :: FilePath -> IO FileType
- readPath :: FilePath -> IO (DirTreeNode [String] FilePath ())
- type DirTreeN s a = DirTreeNode (FileMap (DirTree s a)) s a
- data FileMap a
- toFileList :: FileMap a -> [(String, a)]
- fromFileList :: [(String, a)] -> FileMap a
- (-.>) :: String -> a -> (String, DirTree x a)
- (-|>) :: String -> a -> (String, DirTree a x)
- (-/>) :: String -> [(String, DirTree a b)] -> (String, DirTree a b)
- toDeepFileList :: FileMap (DirTree s a) -> [(FileKey, Either s a)]
- fromDeepFileList :: [(FileKey, Either s a)] -> FileMap (DirTree s a)
- toFileNames :: FileMap a -> [String]
- lookupFileMap :: String -> FileMap a -> Maybe a
- emptyFileMap :: FileMap a
DirTree
A dir tree is a tree of nodes.
DirTree | |
|
Instances
directoryFromFiles :: [(String, DirTree s a)] -> DirTree s a Source #
Constructs a dirtree with a directory
Constructors
fromFiles :: [(FileKey, Either v a)] -> Maybe (DirTree v a) Source #
Create a dirtree from a non-empty list of files.
fromFiles' :: NonEmpty (FileKey, Either v a) -> DirTree v a Source #
Create a dirtree from a non-empty list of files.
Accessors
Traversals
traverseDirTree :: Applicative f => (DirTreeNode (FileMap (f (DirTree s' a'))) s a -> f (DirTreeN s' a')) -> DirTree s a -> f (DirTree s' a') Source #
Traverse a DirTree
traverseDirTree' :: Applicative m => (s -> m s') -> (a -> m a') -> DirTree s a -> m (DirTree s' a') Source #
Traverse a DirTree
itraverseDirTree :: Applicative f => (FileKey -> DirTreeNode (FileMap (f (DirTree s' a'))) s a -> f (DirTreeN s' a')) -> DirTree s a -> f (DirTree s' a') Source #
Traverse over the tree
itraverseDirTree' :: Applicative f => (FileKey -> s -> f s') -> (FileKey -> a -> f a') -> DirTree s a -> f (DirTree s' a') Source #
Traverse over the tree with index. This method uses two functions one symlinks and one for files.
mapDirTree' :: (s -> s') -> (a -> a') -> DirTree s a -> DirTree s' a' Source #
maps over a dirtree
imapDirTree' :: (FileKey -> s -> s') -> (FileKey -> a -> a') -> DirTree s a -> DirTree s' a' Source #
Maps over a DirTree
depthfirst :: Monoid m => (FileKey -> DirTreeNode [String] v a -> m) -> DirTree v a -> m Source #
Recursively iterate over a folder.
foldDirTree :: (DirTreeNode (FileMap m) s a -> m) -> DirTree s a -> m Source #
Folds over a dirtree
foldDirTree' :: Monoid m => (s -> m) -> (a -> m) -> DirTree s a -> m Source #
Folds over a dirtree
ifoldDirTree :: (FileKey -> DirTreeNode (FileMap m) s a -> m) -> DirTree s a -> m Source #
Folds over a DirTree
using the DirTreeNode
.
ifoldDirTree' :: Monoid m => (FileKey -> s -> m) -> (FileKey -> a -> m) -> DirTree s a -> m Source #
Folds over a DirTree
.
flatten :: (s -> DirTree s' a') -> (a -> DirTree s' a') -> DirTree s a -> DirTree s' a' Source #
Flatten a directory tree. This is usefull for following symlinks, or expanding zip-files.
Utils
findNode :: (FileKey -> DirTreeNode [String] v a -> Bool) -> DirTree v a -> Maybe (FileKey, DirTreeNode [String] v a) Source #
Find a file given a predicate that takes a FileKey
and DirTreeNode
.
listNodes :: DirTree v a -> [(FileKey, DirTreeNode [String] v a)] Source #
List all the nodes in the DirTree
.
IO operations
readDirTree :: NFData a => (FilePath -> IO a) -> FilePath -> IO (DirTree Link a) Source #
Reads a DirTree. All file paths are absolute to the filepath
lazyReadDirTree :: (FilePath -> IO a) -> FilePath -> IO (DirTree Link a) Source #
Lazy read a DirTree. This function uses unsafeInterleaveIO
to
lazy interleave load a node. This means that it can be used to efficiently
search of a file. All paths are absolute
writeDirTree :: (FilePath -> a -> IO ()) -> FilePath -> DirTree Link a -> IO () Source #
Reads a DirTree
followLinks :: NFData a => (FilePath -> IO a) -> DirTree Link a -> IO (DirTree Void a) Source #
Follow the links to create the tree. This function might recurse forever.
lazyFollowLinks :: (FilePath -> IO a) -> DirTree Link a -> IO (DirTree Void a) Source #
Like follow links but uses lazy io to only load the recursive folder when needed.
DirTreeNode
A Link
can either be Internal
, pointing to something in the DirTree
or
External
pointing to an absolute FilePath
.
Instances
Eq Link Source # | |
Show Link Source # | |
Generic Link Source # | |
NFData Link Source # | |
Defined in System.DirTree | |
type Rep Link Source # | |
Defined in System.DirTree type Rep Link = D1 (MetaData "Link" "System.DirTree" "dirtree-0.0.1-LpN3AmmKCsNWVMG7Xg0uO" False) (C1 (MetaCons "Internal" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 FileKey)) :+: C1 (MetaCons "External" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 FilePath))) |
data DirTreeNode r s a Source #
A directory tree node. Everything is either a file, a symbolic link, or a directory.
Instances
type FileType = DirTreeNode () () () Source #
A FileType
is just a DirTreeNode
with no contents.
fileTypeOfNode :: DirTreeNode a b c -> FileType Source #
Gets the FileType
of a DirTreeNode
Folds
mapDirTreeNode :: (r -> r') -> (s -> s') -> (a -> a') -> DirTreeNode r s a -> DirTreeNode r' s' a' Source #
We can map over a DirTreeNode
foldDirTreeNode :: (r -> m) -> (s -> m) -> (a -> m) -> DirTreeNode r s a -> m Source #
We can fold over a DirTreeNode by providing a function for each case.
traverseDirTreeNode :: Functor m => (r -> m r') -> (s -> m s') -> (a -> m a') -> DirTreeNode r s a -> m (DirTreeNode r' s' a') Source #
We can fold over a DirTreeNode by providing a function for each case.
IO operations
getFileType :: FilePath -> IO FileType Source #
Check a filepath for Type, throws an IOException if path does not exist.
readPath :: FilePath -> IO (DirTreeNode [String] FilePath ()) Source #
Reads the structure of the filepath
Helpers
type DirTreeN s a = DirTreeNode (FileMap (DirTree s a)) s a Source #
A DirTreeN
is a DirTreeNode
with a the directory as a recursive
DirTree.
FileMap
A map from file names to
Instances
toFileList :: FileMap a -> [(String, a)] Source #
Create a list of pairs of filenames and file values.
fromFileList :: [(String, a)] -> FileMap a Source #
Create a FileMap
from a list of pairs of filenames a file values.
toDeepFileList :: FileMap (DirTree s a) -> [(FileKey, Either s a)] Source #
Returns a list of FileMap
toFileNames :: FileMap a -> [String] Source #
To a list of filenames
emptyFileMap :: FileMap a Source #
empty filemap