Skip to content

Commit

Permalink
Pull weeds
Browse files Browse the repository at this point in the history
  • Loading branch information
pbrisbin committed Oct 18, 2024
1 parent bd87b90 commit 6b83da9
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 87 deletions.
1 change: 0 additions & 1 deletion package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ library:
- microlens
- microlens-mtl
- opt-env-conf
- optparse-applicative
- path
- relude
- semigroups
Expand Down
2 changes: 0 additions & 2 deletions restyler.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ library
Restyler.Monad.Git
Restyler.Monad.ReadFile
Restyler.Monad.WriteFile
Restyler.Opt
Restyler.Options
Restyler.Options.DryRun
Restyler.Options.FailOnDifferences
Expand Down Expand Up @@ -96,7 +95,6 @@ library
, microlens
, microlens-mtl
, opt-env-conf
, optparse-applicative
, path
, relude
, semigroups
Expand Down
15 changes: 0 additions & 15 deletions src/Restyler/AnnotatedException.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ module Restyler.AnnotatedException
, hide
, displayAnnotatedException

-- * Annotated-safe handling
, handleTo
, tryTo

-- * Suppressing exception
, suppressWith
, suppressWarn
Expand All @@ -39,17 +35,6 @@ displayAnnotatedException aex@AnnotatedException {exception} =
, maybe "" (pack . prettyCallStack) $ annotatedExceptionCallStack aex
]

handleTo
:: (MonadUnliftIO m, Exception e1, Exception e2) => (e1 -> e2) -> m a -> m a
handleTo f action = do
r <- tryAnnotated action
case r of
Left AnnotatedException {exception} -> throw $ f exception
Right a -> pure a

tryTo :: (MonadUnliftIO m, Exception e) => (e -> b) -> m a -> m (Either b a)
tryTo f = fmap (first $ f . exception) . tryAnnotated

-- | Suppress any exception and return the given @a@
suppressWith :: MonadUnliftIO m => a -> m a -> m a
suppressWith x = either (const $ pure x) pure <=< tryAnnotated @SomeException
Expand Down
49 changes: 0 additions & 49 deletions src/Restyler/Opt.hs

This file was deleted.

21 changes: 1 addition & 20 deletions src/Restyler/Prelude.hs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,7 @@ import UnliftIO.Exception as X (finally)
import UnliftIO.Temporary as X (withSystemTempDirectory)

import Blammo.Logging.Logger (flushLogger)
import Data.Aeson (Key)
import Data.Aeson.KeyMap (KeyMap)
import Data.Aeson.KeyMap qualified as KeyMap
import Data.List (minimum, minimumBy, (!!))
import Data.List (minimum)

logTrace :: (MonadLogger m, HasCallStack) => Message -> m ()
logTrace = logOther $ LevelOther "trace"
Expand All @@ -66,22 +63,6 @@ minimumMaybe = \case
[] -> Nothing
xs -> Just $ minimum xs

minimumByMaybe :: (a -> a -> Ordering) -> [a] -> Maybe a
minimumByMaybe f = \case
[] -> Nothing
xs -> Just $ minimumBy f xs

-- | Safe version of '(!!)'
(!?) :: [a] -> Int -> Maybe a
xs !? i
| length xs > i = Just $ xs !! i
| otherwise = Nothing

infixl 9 !?

-- | Inverse of @'any'@
none :: Foldable t => (a -> Bool) -> t a -> Bool
none p = not . any p

insertIfMissing :: Key -> v -> KeyMap v -> KeyMap v
insertIfMissing k v m = KeyMap.unionWith const m $ KeyMap.singleton k v

0 comments on commit 6b83da9

Please sign in to comment.