File: Lens.hs

package info (click to toggle)
haskell-network-uri 2.6.4.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 192 kB
  • sloc: haskell: 2,207; makefile: 3
file content (56 lines) | stat: -rw-r--r-- 1,618 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
{-# 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 sa sbt afb s = sbt s <$> afb (sa s)

uriRegNameLens :: Lens' URIAuth String
uriRegNameLens = lens uriRegName (\parent newVal -> parent {uriRegName = newVal})

uriUserInfoLens :: Lens' URIAuth String
uriUserInfoLens =
  lens uriUserInfo (\parent newVal -> parent {uriUserInfo = newVal})

uriPortLens :: Lens' URIAuth String
uriPortLens = lens uriPort (\parent newVal -> parent {uriPort = newVal})

uriAuthorityLens :: Lens' URI (Maybe URIAuth)
uriAuthorityLens =
  lens uriAuthority (\parent newVal -> parent {uriAuthority = newVal})

uriSchemeLens :: Lens' URI String
uriSchemeLens = lens uriScheme (\parent newVal -> parent {uriScheme = newVal})

uriPathLens :: Lens' URI String
uriPathLens = lens uriPath (\parent newVal -> parent {uriPath = newVal})

uriQueryLens :: Lens' URI String
uriQueryLens = lens uriQuery (\parent newVal -> parent {uriQuery = newVal})

uriFragmentLens :: Lens' URI String
uriFragmentLens =
  lens uriFragment (\parent newVal -> parent {uriFragment = newVal})