Skip to content

Commit

Permalink
Resolve #6375: Let export safe* from both Utils.Generic and Simple.Utils
Browse files Browse the repository at this point in the history
So we do with many other stuff
  • Loading branch information
phadej committed Dec 23, 2019
1 parent d230572 commit 809f30a
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 3 deletions.
1 change: 0 additions & 1 deletion Cabal/Distribution/Simple/Compiler.hs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ module Distribution.Simple.Compiler (

import Prelude ()
import Distribution.Compat.Prelude
import Distribution.Utils.Generic(safeLast)
import Distribution.Pretty

import Distribution.Compiler
Expand Down
1 change: 0 additions & 1 deletion Cabal/Distribution/Simple/Configure.hs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ import Distribution.Backpack.DescribeUnitId
import Distribution.Backpack.PreExistingComponent
import Distribution.Backpack.ConfiguredComponent (newPackageDepsBehaviour)
import Distribution.Backpack.Id
import Distribution.Utils.Generic
import Distribution.Utils.LogProgress

import qualified Distribution.Simple.GHC as GHC
Expand Down
1 change: 0 additions & 1 deletion Cabal/Distribution/Simple/HaskellSuite.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import Distribution.PackageDescription
import Distribution.Simple.LocalBuildInfo
import Distribution.System (Platform)
import Distribution.Compat.Exception
import Distribution.Utils.Generic
import Language.Haskell.Extension
import Distribution.Simple.Program.Builtin

Expand Down
2 changes: 2 additions & 0 deletions Cabal/Distribution/Simple/Utils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ module Distribution.Simple.Utils (
ordNubRight,
safeHead,
safeTail,
safeLast,
safeInit,
unintersperse,
wrapText,
wrapLine,
Expand Down
8 changes: 8 additions & 0 deletions Cabal/Distribution/Utils/Generic.hs
Original file line number Diff line number Diff line change
Expand Up @@ -369,21 +369,29 @@ listUnionRight a b = ordNubRight (filter (`Set.notMember` bSet) a) ++ b
bSet = Set.fromList b

-- | A total variant of 'head'.
--
-- @since 3.2.0.0
safeHead :: [a] -> Maybe a
safeHead [] = Nothing
safeHead (x:_) = Just x

-- | A total variant of 'tail'.
--
-- @since 3.2.0.0
safeTail :: [a] -> [a]
safeTail [] = []
safeTail (_:xs) = xs

-- | A total variant of 'last'.
--
-- @since 3.2.0.0
safeLast :: [a] -> Maybe a
safeLast [] = Nothing
safeLast (x:xs) = Just (foldl (\_ a -> a) x xs)

-- | A total variant of 'init'.
--
-- @since 3.2.0.0
safeInit :: [a] -> [a]
safeInit [] = []
safeInit [_] = []
Expand Down

0 comments on commit 809f30a

Please sign in to comment.