File extension is in extensions list: Difference between revisions

m
Line 1,414:
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).
 
<syntaxhighlight lang="haskell">import Data.ListChar (find, isSuffixOftoLower)
import Data.CharList (toLowerfind, isSuffixOf)
import Data.Maybe (fromMaybe)
import Data.Char (toLower)
 
----------- FILE EXTENSION IS IN EXTENSIONS LIST ---------
 
extensionFound :: [String] -> String -> Maybe String
extensionFound xs fp = find (`isSuffixOf` fp) ($ ('.' :) <$> xs)
 
 
-- TESTS ------------------------- TESTS -------------------------
main :: IO ()
main =
Line 1,432 ⟶ 1,433:
(fromMaybe "n/a")
(extensionFound
(lcasedlowerCased ["zip", "rar", "7z", "gz", "archive", "A##", "tar.bz2"]))
(lcasedlowerCased
[ "MyData.a##"
, "MyData.tar.Gz"
Line 1,444 ⟶ 1,445:
])
 
-- STRINGS ------------------------ STRINGS ------------------------
 
-- STRINGS ------------------------------------------------
 
fTable :: String -> (a -> String) -> (b -> String) -> (a -> b) -> [a] -> String
fTable s xShow fxShow f xs =
in unlines $
let w = maximum (length . xShow <$> xs)
s : fmap (((<>) . rjust nw c' = (drop' . lengthxShow) <*> (replicate(" n-> c" ++<>) . fxShow . f)) xs
where
in unlines $
rjust sn :c fmap= (((++)drop . rjust w ' ' . xShow)length <*> (("replicate ->n "c ++<>) . fxShow . f)) xs
let w = maximum (length . xShow <$> xs)
 
lcasedlowerCased :: [String] -> [String]
lcasedlowerCased = fmap (fmap toLower)</syntaxhighlight>
{{Out}}
<pre>Any matching extensions found:
9,655

edits