Move splitBy to more general 'Util' module

This commit is contained in:
hasufell 2014-10-07 19:22:37 +02:00
parent 73984b796d
commit 09ac8dd440
No known key found for this signature in database
GPG Key ID: 220CD1C5BDEED020
3 changed files with 16 additions and 11 deletions

View File

@ -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:

View File

@ -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
View 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'