File extension is in extensions list: Difference between revisions
Content deleted Content added
m →{{header|Haskell}}: Pruned out some noise |
m →{{header|Haskell}}: (Tidied test section) |
||
Line 858:
MyData_v1.0.tar.bz2 True
MyData_v1.0.bz2 False</pre>
We can also express this directly in terms of the '''isSuffix''' function, taking care not to reproduce the small glitch in the draft above, which shows a false positive for '''zip''' in '''.gzip''' (see task description bullet 2).
Line 864 ⟶ 865:
import Data.Maybe (fromMaybe)
import Data.Char (toLower)
extensionFound :: [String] ->
extensionFound
-- TESTS --------------------------------------------------
main :: IO ()
main =
let w = maximum $ length <$> files▼
fTable
▲ (putStrLn . unlines) $
"Any matching extensions found:\n"
id
(fromMaybe
(lcased
▲extensions = ["zip", "rar", "7z", "gz", "archive", "A##", "tar.bz2"]
, "MyData.gzip"▼
, "MyData
, "
, "
])
▲ , "MyData..."
▲ , "MyData"
-- STRINGS ------------------------------------------------
fTable :: String -> (a -> String) -> (b -> String) -> (a -> b) -> [a] -> String
rjust n c = (drop . length) <*> (replicate n c ++)▼
fTable s xShow fxShow f xs =
▲ rjust n c = (drop . length) <*> (replicate n c ++)
in unlines $
s : fmap (((++) . rjust w ' ' . xShow) <*> ((" -> " ++) . fxShow . f)) xs
lcased :: [String] -> [String]
lcased = fmap (fmap toLower)</lang>
{{Out}}
<pre>Any matching extensions found:
▲<pre> MyData.a## -> .a##
▲ MyData.tar.Gz -> .gz
mydata... -> n/a
MyData_v1.0.tar.bz2 -> .tar.bz2▼
mydata_v1.0.bz2 -> n/a</pre>
=={{header|J}}==
|