bencoding-lens-0.1.0.0: Lenses for bencoded data.
Copyright(c) Joseph Morag 2021-2022
LicenseBSD3
MaintainerJoseph Morag <jm@josephmorag.com>
Stabilityexperimental
Portabilitynon-portable
Safe HaskellSafe-Inferred
LanguageHaskell2010

Data.BEncode.Lens

Description

This module exports orphan instances for Ixed BValue, Plated BValue, Ixed BDictMap, Plated BDictMap, Traversable BDictMap, FunctorWithIndex BDictMap, FoldableWithIndex BDictMap, and TraversbaleWithIndex BDictMap.

Synopsis

Prisms

class AsBValue t where Source #

Things that can be treated as a BValue. Instances are provided for strict and lazy ByteString as well as BValues themselves.

Minimal complete definition

_BValue

Methods

_BValue :: Prism' t BValue Source #

_BInteger :: Prism' t BInteger Source #

>>> ("i3e" :: ByteString) ^? _BInteger
Just 3

_BString :: Prism' t BString Source #

>>> ("0:" :: ByteString) ^? _BString
Just ""
>>> ("4:spam" :: ByteString) ^? _BString
Just "spam"

_BList :: Prism' t BList Source #

>>> ("le" :: ByteString) ^? _BList
Just []
>>> ("l4:spam4:eggse" :: ByteString) ^? _BList == Just [BString "spam", BString "eggs"]
True

_BDict :: Prism' t BDict Source #

>>> ("de" :: ByteString) ^? _BDict
Just Nil
>>> ("d3:cow3:moo4:spam4:eggse" :: ByteString) ^? _BDict == Just (Cons "cow" (BString "moo") (Cons "spam" (BString "eggs") Nil))
True

BDicts and BLists

members :: AsBValue t => IndexedTraversal' BKey t BValue Source #

>>> ("d3:cow3:moo4:spam4:eggse" :: ByteString) ^@.. members
[("cow",BString "moo"),("spam",BString "eggs")]

key :: AsBValue t => BKey -> Traversal' t BValue Source #

>>> ("d3:cow3:moo4:spam4:eggse" :: ByteString) ^? key "cow"
Just (BString "moo")

nth :: AsBValue t => Int -> Traversal' t BValue Source #

>>> ("li0ei1ee" :: ByteString) ^? nth 0
Just (BInteger 0)

values :: AsBValue t => IndexedTraversal' Int t BValue Source #

>>> ("ll1:ae3:cow3:moo4:spam4:eggse" :: ByteString) ^.. values
[BList [BString "a"],BString "cow",BString "moo",BString "spam",BString "eggs"]

Orphan instances

Traversable BDictMap Source # 
Instance details

Methods

traverse :: Applicative f => (a -> f b) -> BDictMap a -> f (BDictMap b) #

sequenceA :: Applicative f => BDictMap (f a) -> f (BDictMap a) #

mapM :: Monad m => (a -> m b) -> BDictMap a -> m (BDictMap b) #

sequence :: Monad m => BDictMap (m a) -> m (BDictMap a) #

Ixed BValue Source # 
Instance details

Plated BValue Source # 
Instance details

TraversableWithIndex BKey BDictMap Source # 
Instance details

Methods

itraverse :: Applicative f => (BKey -> a -> f b) -> BDictMap a -> f (BDictMap b) #

FoldableWithIndex BKey BDictMap Source # 
Instance details

Methods

ifoldMap :: Monoid m => (BKey -> a -> m) -> BDictMap a -> m #

ifoldMap' :: Monoid m => (BKey -> a -> m) -> BDictMap a -> m #

ifoldr :: (BKey -> a -> b -> b) -> b -> BDictMap a -> b #

ifoldl :: (BKey -> b -> a -> b) -> b -> BDictMap a -> b #

ifoldr' :: (BKey -> a -> b -> b) -> b -> BDictMap a -> b #

ifoldl' :: (BKey -> b -> a -> b) -> b -> BDictMap a -> b #

FunctorWithIndex BKey BDictMap Source # 
Instance details

Methods

imap :: (BKey -> a -> b) -> BDictMap a -> BDictMap b #

Ixed (BDictMap a) Source # 
Instance details

Methods

ix :: Index (BDictMap a) -> Traversal' (BDictMap a) (IxValue (BDictMap a)) #

At (BDictMap a) Source # 
Instance details

Methods

at :: Index (BDictMap a) -> Lens' (BDictMap a) (Maybe (IxValue (BDictMap a))) #