Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
|
|
@ -0,0 +1,23 @@
|
|||
import Data.List
|
||||
|
||||
-- Return the common prefix of two lists.
|
||||
commonPrefix2 (x:xs) (y:ys) | x == y = x : commonPrefix2 xs ys
|
||||
commonPrefix2 _ _ = []
|
||||
|
||||
-- Return the common prefix of zero or more lists.
|
||||
commonPrefix (xs:xss) = foldr commonPrefix2 xs xss
|
||||
commonPrefix _ = []
|
||||
|
||||
-- Split a string into path components.
|
||||
splitPath = groupBy (\_ c -> c /= '/')
|
||||
|
||||
-- Return the common prefix of zero or more paths.
|
||||
-- Note that '/' by itself is not considered a path component,
|
||||
-- so "/" and "/foo" are treated as having nothing in common.
|
||||
commonDirPath = concat . commonPrefix . map splitPath
|
||||
|
||||
main = putStrLn $ commonDirPath [
|
||||
"/home/user1/tmp/coverage/test",
|
||||
"/home/user1/tmp/covert/operator",
|
||||
"/home/user1/tmp/coven/members"
|
||||
]
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
import Data.List (transpose, intercalate)
|
||||
import Data.List.Split (splitOn)
|
||||
|
||||
|
||||
------------------ COMMON DIRECTORY PATH -----------------
|
||||
|
||||
commonDirectoryPath :: [String] -> String
|
||||
commonDirectoryPath [] = []
|
||||
commonDirectoryPath xs =
|
||||
intercalate "/" $
|
||||
head <$> takeWhile ((all . (==) . head) <*> tail) $
|
||||
transpose (splitOn "/" <$> xs)
|
||||
|
||||
--------------------------- TEST -------------------------
|
||||
main :: IO ()
|
||||
main =
|
||||
(putStrLn . commonDirectoryPath)
|
||||
[ "/home/user1/tmp/coverage/test"
|
||||
, "/home/user1/tmp/covert/operator"
|
||||
, "/home/user1/tmp/coven/members"
|
||||
]
|
||||
Loading…
Add table
Add a link
Reference in a new issue