File extension is in extensions list: Difference between revisions
File extension is in extensions list (view source)
Revision as of 04:55, 27 January 2023
, 1 year ago→{{header|Haskell}}: Tidied
m (→{{header|Haskell}}: Tidied) |
|||
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.
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)
-
main :: IO ()
main =
Line 1,432 ⟶ 1,433:
(fromMaybe "n/a")
(extensionFound
(
(
[ "MyData.a##"
, "MyData.tar.Gz"
Line 1,444 ⟶ 1,445:
])
▲-- STRINGS ------------------------------------------------
fTable :: String -> (a -> String) -> (b -> String) -> (a -> b) -> [a] -> String
fTable s xShow fxShow f xs =
let w = maximum (length . xShow <$> xs)▼
s : fmap (((<>) . rjust
where
▲ in unlines $
rjust
{{Out}}
<pre>Any matching extensions found:
|