From 09ac8dd44091a79a33d7140b25802fd893e75ecc Mon Sep 17 00:00:00 2001 From: hasufell Date: Tue, 7 Oct 2014 19:22:37 +0200 Subject: [PATCH] Move splitBy to more general 'Util' module --- CG2.cabal | 2 +- OS/FileExt.hs | 12 ++---------- Util.hs | 13 +++++++++++++ 3 files changed, 16 insertions(+), 11 deletions(-) create mode 100644 Util.hs diff --git a/CG2.cabal b/CG2.cabal index 3460659..0e43c09 100644 --- a/CG2.cabal +++ b/CG2.cabal @@ -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: diff --git a/OS/FileExt.hs b/OS/FileExt.hs index 571f63f..e32048d 100644 --- a/OS/FileExt.hs +++ b/OS/FileExt.hs @@ -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' diff --git a/Util.hs b/Util.hs new file mode 100644 index 0000000..95c0524 --- /dev/null +++ b/Util.hs @@ -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'