RosettaCodeData/Task/Find-common-directory-path/Haskell/find-common-directory-path-2.hs

22 lines
577 B
Haskell
Raw Permalink Normal View History

2023-07-01 11:58:00 -04:00
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"
]