From e55a17a98f71431aeed1259df14ae2bb12ff7182 Mon Sep 17 00:00:00 2001 From: joneshf Date: Thu, 5 Jul 2018 07:34:01 -0700 Subject: [PATCH 1/3] Drop lens dependency We really are only using it for convenience. Since we rarely change this code. we can take the hit on convenience and inline the functions. We give more concrete types to some of these helpers. We can also remove the use of lenses entirely if it comes to that. --- servant-ruby.cabal | 1 - src/Servant/Ruby.hs | 36 ++++++++++++++++++++++++++++++++---- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/servant-ruby.cabal b/servant-ruby.cabal index 18b2fcd..6b38420 100644 --- a/servant-ruby.cabal +++ b/servant-ruby.cabal @@ -19,7 +19,6 @@ library exposed-modules: Servant.Ruby build-depends: base >= 4.8 && < 5 , casing >= 0.1 && < 0.2 - , lens >= 4.15 && < 4.17 , servant-foreign >= 0.9 && < 0.12 , text >= 1.2 && < 1.3 default-language: Haskell2010 diff --git a/src/Servant/Ruby.hs b/src/Servant/Ruby.hs index 1621ae8..699fc16 100644 --- a/src/Servant/Ruby.hs +++ b/src/Servant/Ruby.hs @@ -1,6 +1,7 @@ {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE RankNTypes #-} {-# LANGUAGE RecordWildCards #-} {-| @@ -15,9 +16,10 @@ Stability: Experimental module Servant.Ruby (NameSpace(..), ruby) where -import Control.Lens (filtered, folded, to, view, (^.), (^..), (&)) - -import Data.Monoid ((<>)) +import Data.Foldable (toList) +import Data.Function ((&)) +import Data.Functor.Const (Const(Const, getConst)) +import Data.Monoid (Endo(Endo, appEndo), (<>)) import Data.Proxy (Proxy(Proxy)) import Data.Text (Text) import Data.Text.Encoding (decodeUtf8') @@ -231,7 +233,9 @@ public indent req = ++ headerArgs segments :: [Segment NoContent] - segments = req ^. reqUrl.path^..folded.filtered isCapture + segments = filter isCapture paths + where + paths = toList (req ^. reqUrl.path) queryparams :: [QueryArg NoContent] queryparams = req ^.. reqUrl.queryStr.traverse @@ -325,3 +329,27 @@ prop> \str -> snake (snake $ T.pack str) == snake (T.pack str) -} snake :: Text -> Text snake = T.pack . quietSnake . T.unpack + +-- optics + +to :: (s -> a) -> Getting a s a +to f a2fa s = s <$ (a2fa $ f s) +{-# INLINE to #-} + +view :: Getting a s a -> s -> a +view s2a s = getConst (s2a Const s) +{-# INLINE view #-} + +infixl 8 ^. + +(^.) :: s -> Getting a s a -> a +x ^. l = view l x +{-# INLINE (^.) #-} + +infixl 8 ^.. + +(^..) :: s -> Getting (Endo [a]) s a -> [a] +x ^.. l = appEndo (getConst $ l (Const . Endo . (:)) x) [] +{-# INLINE (^..) #-} + +type Getting r s a = (a -> Const r a) -> s -> Const r s From 1b1c05e0058e9e3c0e9f4ee4bd0cb5bb5e67fff9 Mon Sep 17 00:00:00 2001 From: joneshf Date: Thu, 5 Jul 2018 13:53:22 -0700 Subject: [PATCH 2/3] Use `Control.Applicative` as the import `Data.Functor.Const` didn't exist until 4.9.0.0 of `base`. Rather than use `CPP` extensions, just use the other module that re-exports it. --- src/Servant/Ruby.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Servant/Ruby.hs b/src/Servant/Ruby.hs index 699fc16..498e905 100644 --- a/src/Servant/Ruby.hs +++ b/src/Servant/Ruby.hs @@ -16,9 +16,9 @@ Stability: Experimental module Servant.Ruby (NameSpace(..), ruby) where +import Control.Applicative (Const(Const, getConst)) import Data.Foldable (toList) import Data.Function ((&)) -import Data.Functor.Const (Const(Const, getConst)) import Data.Monoid (Endo(Endo, appEndo), (<>)) import Data.Proxy (Proxy(Proxy)) import Data.Text (Text) From 31eaaa28ee0575012755e2f57c88a3e443e1d09c Mon Sep 17 00:00:00 2001 From: joneshf Date: Thu, 5 Jul 2018 13:55:53 -0700 Subject: [PATCH 3/3] Test on GHC 8.4.2 as well --- .travis.yml | 3 +++ servant-ruby.cabal | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 7a80574..21a22e8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,6 +22,9 @@ matrix: - env: CABALVER=1.24 GHCVER=8.2.2 compiler: ": #GHC 8.2.2" addons: {apt: {packages: [cabal-install-1.24,ghc-8.2.2], sources: [hvr-ghc]}} + - env: CABALVER=1.24 GHCVER=8.4.2 + compiler: ": #GHC 8.4.2" + addons: {apt: {packages: [cabal-install-1.24,ghc-8.4.2], sources: [hvr-ghc]}} before_install: - unset CC diff --git a/servant-ruby.cabal b/servant-ruby.cabal index 6b38420..a7399e3 100644 --- a/servant-ruby.cabal +++ b/servant-ruby.cabal @@ -12,7 +12,7 @@ category: Servant, Web build-type: Simple extra-source-files: README.md cabal-version: >=1.10 -tested-with: GHC == 7.10.3, GHC == 8.0.2, GHC == 8.2.2 +tested-with: GHC == 7.10.3, GHC == 8.0.2, GHC == 8.2.2, GHC == 8.4.2 library hs-source-dirs: src