Browse Source

yet more lenses

master
Philipp Balzarek 12 years ago
parent
commit
022b8885f4
  1. 5
      source/Network/Xmpp.hs
  2. 28
      source/Network/Xmpp/Lens.hs

5
source/Network/Xmpp.hs

@ -197,6 +197,11 @@ module Network.Xmpp
, establishSessionL , establishSessionL
, tlsBehaviourL , tlsBehaviourL
, tlsParamsL , tlsParamsL
-- ** SessionConfiguration
, streamConfigurationL
, onConnectionClosedL
, sessionStanzaIDsL
, ensableRoster
-- * Threads -- * Threads
, dupSession , dupSession
-- * Miscellaneous -- * Miscellaneous

28
source/Network/Xmpp/Lens.hs

@ -39,7 +39,11 @@ module Network.Xmpp.Lens
, establishSessionL , establishSessionL
, tlsBehaviourL , tlsBehaviourL
, tlsParamsL , tlsParamsL
-- ** SessionConfiguration
, streamConfigurationL
, onConnectionClosedL
, sessionStanzaIDsL
, ensableRoster
) )
where where
@ -51,6 +55,7 @@ import Data.XML.Types(Element)
import Network.DNS(ResolvConf) import Network.DNS(ResolvConf)
import Network.TLS (TLSParams) import Network.TLS (TLSParams)
import Network.Xmpp.Types import Network.Xmpp.Types
import Network.Xmpp.Concurrent.Types
-- | Van-Laarhoven lenses. -- | Van-Laarhoven lenses.
type Lens a b = Functor f => (b -> f b) -> a -> f a type Lens a b = Functor f => (b -> f b) -> a -> f a
@ -291,6 +296,27 @@ tlsParamsL :: Lens StreamConfiguration TLSParams
tlsParamsL inj sc@StreamConfiguration{tlsParams = x} tlsParamsL inj sc@StreamConfiguration{tlsParams = x}
= (\x' -> sc{tlsParams = x'}) <$> inj x = (\x' -> sc{tlsParams = x'}) <$> inj x
-- SessioConfiguration
-----------------------
streamConfigurationL :: Lens SessionConfiguration StreamConfiguration
streamConfigurationL inj sc@SessionConfiguration{sessionStreamConfiguration = x}
= (\x' -> sc{sessionStreamConfiguration = x'}) <$> inj x
onConnectionClosedL :: Lens SessionConfiguration (Session -> XmppFailure -> IO ())
onConnectionClosedL inj sc@SessionConfiguration{onConnectionClosed = x}
= (\x' -> sc{onConnectionClosed = x'}) <$> inj x
sessionStanzaIDsL :: Lens SessionConfiguration (IO (IO Text))
sessionStanzaIDsL inj sc@SessionConfiguration{sessionStanzaIDs = x}
= (\x' -> sc{sessionStanzaIDs = x'}) <$> inj x
ensableRoster :: Lens SessionConfiguration Bool
ensableRoster inj sc@SessionConfiguration{enableRoster = x}
= (\x' -> sc{enableRoster = x'}) <$> inj x
pluginsL inj sc@SessionConfiguration{plugins = x}
= (\x' -> sc{plugins = x'}) <$> inj x
-- | Read the value the lens is pointing to -- | Read the value the lens is pointing to
view :: Lens a b -> a -> b view :: Lens a b -> a -> b
view l x = getConst $ l Const x view l x = getConst $ l Const x

Loading…
Cancel
Save