Find common directory path: Difference between revisions

→‎{{header|Haskell}}: Tidied applicative version.
(→‎{{header|Haskell}}: Tidied applicative version.)
Line 1,019:
]</lang>
 
Or perhaps, expressed directly in applicative terms:
<lang haskell>import Data.List (transpose, intercalate)
import Data.List.Split (splitOn)
 
import Data.Bool (bool)
 
------------------ COMMON DIRECTORY PATH -----------------
cdp :: [String] -> String
 
cdp =
cdpcommonDirectoryPath :: [String] -> String
flip
commonDirectoryPath [] = []
(bool .
commonDirectoryPath xs =
intercalate "/" .$
fmap head .
head <$> takeWhile ((all . (==) . head) <*> tail) . transpose . fmap (splitOn "/"))$
transpose ([])splitOn "/" <*$> xs)
 
null
--------------------------- TEST -------------------------
main :: IO ()
main =
(putStrLn . cdpcommonDirectoryPath)
[ "/home/user1/tmp/coverage/test"
, "/home/user1/tmp/covert/operator"
9,655

edits