Skip to content

Commit 8890426

Browse files
andreasabelmergify[bot]
authored andcommitted
Cosmetics in cabal-install...Utils: ifNotM is better abstraction then notM
1 parent d5dbf56 commit 8890426

File tree

1 file changed

+6
-6
lines changed
  • cabal-install/src/Distribution/Client

1 file changed

+6
-6
lines changed

cabal-install/src/Distribution/Client/Utils.hs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ getCurrentYear = do
431431
-- | From System.Directory.Extra
432432
-- https://hackage.haskell.org/package/extra-1.7.9
433433
listFilesInside :: (FilePath -> IO Bool) -> FilePath -> IO [FilePath]
434-
listFilesInside test dir = ifM (notM $ test $ dropTrailingPathSeparator dir) (pure []) $ do
434+
listFilesInside test dir = ifNotM (test $ dropTrailingPathSeparator dir) (pure []) $ do
435435
(dirs,files) <- partitionM doesDirectoryExist =<< listContents dir
436436
rest <- concatMapM (listFilesInside test) dirs
437437
pure $ files ++ rest
@@ -453,6 +453,11 @@ listContents dir = do
453453
ifM :: Monad m => m Bool -> m a -> m a -> m a
454454
ifM b t f = do b' <- b; if b' then t else f
455455

456+
-- | 'ifM' with swapped branches:
457+
-- @ifNotM b t f = ifM (not <$> b) t f@
458+
ifNotM :: Monad m => m Bool -> m a -> m a -> m a
459+
ifNotM = flip . ifM
460+
456461
-- | From Control.Monad.Extra
457462
-- https://hackage.haskell.org/package/extra-1.7.9
458463
concatMapM :: Monad m => (a -> m [b]) -> [a] -> m [b]
@@ -469,11 +474,6 @@ partitionM f (x:xs) = do
469474
(as,bs) <- partitionM f xs
470475
pure ([x | res]++as, [x | not res]++bs)
471476

472-
-- | From Control.Monad.Extra
473-
-- https://hackage.haskell.org/package/extra-1.7.9
474-
notM :: Functor m => m Bool -> m Bool
475-
notM = fmap not
476-
477477
safeRead :: Read a => String -> Maybe a
478478
safeRead s
479479
| [(x, "")] <- reads s = Just x

0 commit comments

Comments
 (0)