Move splitBy to more general 'Util' module
This commit is contained in:
parent
73984b796d
commit
09ac8dd440
@ -54,7 +54,7 @@ executable CG2
|
||||
main-is: Main.hs
|
||||
|
||||
-- Modules included in this executable, other than Main.
|
||||
other-modules: Diagram Gtk Class.Defaults Parser.Meshparser Parser.Core OS.FileExt LinearAlgebra.Vector
|
||||
other-modules: Diagram Gtk Util Class.Defaults Parser.Meshparser Parser.Core OS.FileExt LinearAlgebra.Vector
|
||||
|
||||
-- LANGUAGE extensions used by modules in this package.
|
||||
-- other-extensions:
|
||||
|
@ -2,6 +2,8 @@
|
||||
|
||||
module OS.FileExt where
|
||||
|
||||
import Util
|
||||
|
||||
|
||||
-- |Compare the extension of a file with the given String.
|
||||
cmpExt :: String -> FilePath -> Bool
|
||||
@ -22,13 +24,3 @@ getExt fp
|
||||
-- |Check if the file has an extension.
|
||||
hasExt :: FilePath -> Bool
|
||||
hasExt = (>1) . length . splitBy (== '.')
|
||||
|
||||
|
||||
-- |Split an array into subarrays depending on a given condition.
|
||||
splitBy :: (a -> Bool) -- ^ condition
|
||||
-> [a] -- ^ array to split
|
||||
-> [[a]] -- ^ splitted array
|
||||
splitBy f s = case dropWhile f s of
|
||||
[] -> []
|
||||
s' -> w : splitBy f s''
|
||||
where (w, s'') = break f s'
|
||||
|
13
Util.hs
Normal file
13
Util.hs
Normal file
@ -0,0 +1,13 @@
|
||||
{-# OPTIONS_HADDOCK ignore-exports #-}
|
||||
|
||||
module Util where
|
||||
|
||||
|
||||
-- |Split an array into subarrays depending on a given condition.
|
||||
splitBy :: (a -> Bool) -- ^ condition
|
||||
-> [a] -- ^ array to split
|
||||
-> [[a]] -- ^ splitted array
|
||||
splitBy f s = case dropWhile f s of
|
||||
[] -> []
|
||||
s' -> w : splitBy f s''
|
||||
where (w, s'') = break f s'
|
Loading…
Reference in New Issue
Block a user