Merge pull request #19 from thomie/splitDirectories
authorNeil Mitchell <ndmitchell@gmail.com>
Sun, 26 Oct 2014 21:24:14 +0000 (21:24 +0000)
committerNeil Mitchell <ndmitchell@gmail.com>
Sun, 26 Oct 2014 21:24:14 +0000 (21:24 +0000)
Refactor splitDirectories

System/FilePath/Internal.hs

index 8fc9314..832192d 100644 (file)
@@ -644,15 +644,7 @@ splitPath x = [drive | drive /= ""] ++ f path
 -- > Posix:   Valid x => joinPath (splitDirectories x) `equalFilePath` x
 -- > splitDirectories "" == []
 splitDirectories :: FilePath -> [FilePath]
-splitDirectories path =
-        if hasDrive path then head pathComponents : f (tail pathComponents)
-        else f pathComponents
-    where
-        pathComponents = splitPath path
-
-        f = map g
-        g x = if null res then x else res
-            where res = takeWhile (not . isPathSeparator) x
+splitDirectories = map dropTrailingPathSeparator . splitPath
 
 
 -- | Join path elements back together.