Skip to content

Commit

Permalink
remove 'safe' dependencies, use Relude tools instead
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-martin committed Jul 30, 2024
1 parent 8de047d commit 35e84b5
Show file tree
Hide file tree
Showing 7 changed files with 5 additions and 12 deletions.
1 change: 0 additions & 1 deletion freckle-http/freckle-http.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ library
, network-uri
, relude
, retry >=0.8.1.0
, safe
, semigroupoids
, serialise
, text
Expand Down
5 changes: 2 additions & 3 deletions freckle-http/library/Freckle/App/Http/Cache.hs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ import Network.HTTP.Types.Header
, hVary
)
import Network.HTTP.Types.Status (Status, statusCode)
import Safe (readMay)

data HttpCacheSettings m t = HttpCacheSettings
{ shared :: Bool
Expand Down Expand Up @@ -276,7 +275,7 @@ readCacheControl = go . CI.foldCase
go = \case
"private" -> Just Private
"no-store" -> Just NoStore
h | Just s <- BS8.stripPrefix "max-age=" h -> MaxAge <$> readMay (BS8.unpack s)
h | Just s <- BS8.stripPrefix "max-age=" h -> MaxAge <$> readMaybe (BS8.unpack s)
_ -> Nothing

getCacheControl :: HasHeaders a => a -> [CacheControl]
Expand Down Expand Up @@ -316,7 +315,7 @@ getResponseHeaders resp =
{ cacheControl = getCacheControl resp
, age = fromMaybe 0 $ do
h <- lookupHeader hAge resp
readMay $ BS8.unpack h
readMaybe $ BS8.unpack h
, expires = do
h <- lookupHeader hExpires resp
parseTimeM True defaultTimeLocale httpDateFormat $ BS8.unpack h
Expand Down
5 changes: 2 additions & 3 deletions freckle-http/library/Freckle/App/Test/Http.hs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import Control.Lens (Lens', lens, view, (.~), (<>~))
import Data.Aeson (ToJSON, encode)
import Data.ByteString.Lazy qualified as BSL
import Data.List (stripPrefix)
import Data.Traversable (for)
import Freckle.App.Http (MonadHttp (..))
import Freckle.App.Test.Http.MatchRequest
import Network.HTTP.Client (Request, Response)
Expand All @@ -58,8 +59,6 @@ import Network.HTTP.Types.Status (Status, status200)
import System.Directory (doesFileExist)
import System.FilePath (addTrailingPathSeparator)
import System.FilePath.Glob (globDir1)
import Safe(headMay)
import Data.Traversable (for)

-- | Respond to a 'Request' with the first 'HttpStub' to match
--
Expand All @@ -82,7 +81,7 @@ httpStubbed
-> Request
-> Response BSL.ByteString
httpStubbed stubs req =
maybe (error errorMessage) (toResponse req) $ headMay matched
maybe (error errorMessage) (toResponse req) $ viaNonEmpty head matched
where
(unmatched, matched) =
partitionEithers
Expand Down
1 change: 0 additions & 1 deletion freckle-http/package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ library:
- network-uri
- relude
- retry >= 0.8.1.0 # retryingDynamic
- safe
- serialise
- semigroupoids
- text
Expand Down
1 change: 0 additions & 1 deletion freckle-memcached/freckle-memcached.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ test-suite spec
, lens-aeson
, memcache
, relude
, safe
, text
, unliftio
default-language: GHC2021
Expand Down
1 change: 0 additions & 1 deletion freckle-memcached/package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,5 @@ tests:
- lens-aeson
- memcache
- relude
- safe
- text
- unliftio
3 changes: 1 addition & 2 deletions freckle-memcached/tests/Freckle/App/Memcached/ServersSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import Relude
import Control.Error.Util (hush)
import Database.Memcache.Client qualified as Memcache
import Freckle.App.Memcached.Servers
import Safe (headMay)
import Test.Hspec

spec :: Spec
Expand Down Expand Up @@ -75,7 +74,7 @@ spec = do
[Memcache.NoAuth, Memcache.NoAuth, Memcache.Auth "u" "p"]

readServerSpec :: String -> Maybe Memcache.ServerSpec
readServerSpec = headMay <=< readServerSpecs
readServerSpec = viaNonEmpty head <=< readServerSpecs

readServerSpecs :: String -> Maybe [Memcache.ServerSpec]
readServerSpecs = fmap toServerSpecs . hush . readMemcachedServers
Expand Down

0 comments on commit 35e84b5

Please sign in to comment.