{-# LANGUAGE CPP #-}
{-# LANGUAGE Rank2Types #-}
#if __GLASGOW_HASKELL__ > 704
{-# LANGUAGE Safe #-}
#elif __GLASGOW_HASKELL__ > 702
{-# LANGUAGE Trustworthy #-}
#endif
-- | Network uri lenses
module Network.URI.Lens
  ( uriRegNameLens
  , uriUserInfoLens
  , uriPortLens
  , uriAuthorityLens
  , uriSchemeLens
  , uriPathLens
  , uriQueryLens
  , uriFragmentLens
  ) where

#if __GLASGOW_HASKELL__ < 710
import           Control.Applicative
#endif
import           Network.URI

type Lens' s a = Lens s s a a
type Lens s t a b = forall f. Functor f => (a -> f b) -> s -> f t

lens :: (s -> a) -> (s -> b -> t) -> Lens s t a b
lens :: forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens s -> a
sa s -> b -> t
sbt a -> f b
afb s
s = s -> b -> t
sbt s
s (b -> t) -> f b -> f t
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> f b
afb (s -> a
sa s
s)

uriRegNameLens :: Lens' URIAuth String
uriRegNameLens :: Lens' URIAuth String
uriRegNameLens = (URIAuth -> String)
-> (URIAuth -> String -> URIAuth) -> Lens' URIAuth String
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens URIAuth -> String
uriRegName (\URIAuth
parent String
newVal -> URIAuth
parent {uriRegName = newVal})

uriUserInfoLens :: Lens' URIAuth String
uriUserInfoLens :: Lens' URIAuth String
uriUserInfoLens =
  (URIAuth -> String)
-> (URIAuth -> String -> URIAuth) -> Lens' URIAuth String
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens URIAuth -> String
uriUserInfo (\URIAuth
parent String
newVal -> URIAuth
parent {uriUserInfo = newVal})

uriPortLens :: Lens' URIAuth String
uriPortLens :: Lens' URIAuth String
uriPortLens = (URIAuth -> String)
-> (URIAuth -> String -> URIAuth) -> Lens' URIAuth String
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens URIAuth -> String
uriPort (\URIAuth
parent String
newVal -> URIAuth
parent {uriPort = newVal})

uriAuthorityLens :: Lens' URI (Maybe URIAuth)
uriAuthorityLens :: Lens' URI (Maybe URIAuth)
uriAuthorityLens =
  (URI -> Maybe URIAuth)
-> (URI -> Maybe URIAuth -> URI) -> Lens' URI (Maybe URIAuth)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens URI -> Maybe URIAuth
uriAuthority (\URI
parent Maybe URIAuth
newVal -> URI
parent {uriAuthority = newVal})

uriSchemeLens :: Lens' URI String
uriSchemeLens :: Lens' URI String
uriSchemeLens = (URI -> String) -> (URI -> String -> URI) -> Lens' URI String
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens URI -> String
uriScheme (\URI
parent String
newVal -> URI
parent {uriScheme = newVal})

uriPathLens :: Lens' URI String
uriPathLens :: Lens' URI String
uriPathLens = (URI -> String) -> (URI -> String -> URI) -> Lens' URI String
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens URI -> String
uriPath (\URI
parent String
newVal -> URI
parent {uriPath = newVal})

uriQueryLens :: Lens' URI String
uriQueryLens :: Lens' URI String
uriQueryLens = (URI -> String) -> (URI -> String -> URI) -> Lens' URI String
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens URI -> String
uriQuery (\URI
parent String
newVal -> URI
parent {uriQuery = newVal})

uriFragmentLens :: Lens' URI String
uriFragmentLens :: Lens' URI String
uriFragmentLens =
  (URI -> String) -> (URI -> String -> URI) -> Lens' URI String
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens URI -> String
uriFragment (\URI
parent String
newVal -> URI
parent {uriFragment = newVal})