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 18b2fcd..a7399e3 100644 --- a/servant-ruby.cabal +++ b/servant-ruby.cabal @@ -12,14 +12,13 @@ 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 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..498e905 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 Control.Applicative (Const(Const, getConst)) +import Data.Foldable (toList) +import Data.Function ((&)) +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