bson-lens-0.1.1: BSON lenses

Safe HaskellNone
LanguageHaskell2010

Data.Bson.Lens

Synopsis

Documentation

key :: AsDocument t => Label -> Traversal' t Value Source

Like ix, but for Document values with Text indices

>>> ["someKey" := Float 3.0] ^? key "someKey"
Just 3.0

values :: AsValue v => IndexedTraversal' Int v Value Source

An indexed Traversal into Array elements

>>> Array [String "hey", Float 2.0] ^.. values
["hey", 2.0]
>>> "Array [Float 2.0,Float 3.0,Float 4.0]" & values . _Float *~ 2.0
"[4.0,6.0,8.0]"

fields :: AsDocument v => IndexedTraversal' Int v Field Source

An indexed Traversal into Document fields

>>> Array [Doc ["doc1" := Float 3.0], Doc ["doc2" := Bool True]] ^.. values . fields
[ key: 3.0, key2: True ]

members :: AsDocument v => Traversal' v Value Source

A Traversal into Document values

>>> ["key" := Float 3.0, "key2" := Bool True] & members . _Float *~ 2
[ key: 6.0, key2: True ]

nth :: AsValue v => Int -> Traversal' v Value Source

Like ix, but for Arrays with Int indexes

>>> "Array [Float 1.0, Float 2.0, Float 3.0]" ^? nth 1
Just 2.0
>>> "Array [Float 1.0, Float 2.0, Float 3.0]" & nth 1 .~ Float 20.0
"[1.0,20.0,3.0]"

labels :: AsDocument v => Traversal' v Label Source

A Traversal into Document keys

>>> ["key" := Float 3.0, "key2" := Bool True] & labels %~ Data.Text.toUpper
["KEY": 3.0, "KEY2": True]

class AsValue t where Source

Minimal complete definition

Nothing

Methods

_Value :: Traversal' t Value Source

A traversal for types that contain Values

>>> ("key" .= Bool True) ^? _Value
Just True
>>> Doc ["key" .= Bool True] ^? _Value
Just [ key: True]

class AsDocument t where Source

Minimal complete definition

Nothing

Methods

_Document :: Traversal' t Document Source

A traversal for types that contain documents

>>> ["key" .= Bool True] ^? _Document
Just [ key: True]
>>> Doc ["key" .= Bool True] ^? _Document
Just [ key: True]