Find common directory path: Difference between revisions

→‎{{header|Haskell}}: Tidied 2nd version
(Add Rust implementation)
(→‎{{header|Haskell}}: Tidied 2nd version)
Line 932:
<lang haskell>import Data.List (transpose, intercalate)
import Data.List.Split (splitOn)
import Data.Bool (bool)
 
cdp :: [String] -> String
cdp [] = []xs
cdp | null xs = []
let| same []otherwise = True
in (intercalate "/" $.
same (x:xs) = all (x ==) xs
fmap head $. takeWhile same $. transpose . fmap (splitOn "/" <$> xs))
in intercalate "/" $
xs
fmap head $ takeWhile same $ transpose (splitOn "/" <$> xs)
 
same
:: Eq a
=> [a] -> Bool
same [] = True
same (x:xs) = all (x ==) xs
 
main :: IO ()
9,655

edits