Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- class Monoid ( Share a) => FromSharedCBOR a where
- newtype Interns a = Interns [ Intern a]
-
data
Intern
a =
Intern
{
- internMaybe :: a -> Maybe a
- internWeight :: ! Int
- fromSharedLensCBOR :: FromSharedCBOR b => SimpleGetter bs ( Share b) -> StateT bs ( Decoder s) b
- fromSharedPlusLensCBOR :: FromSharedCBOR b => Lens' bs ( Share b) -> StateT bs ( Decoder s) b
- fromNotSharedCBOR :: FromSharedCBOR a => Decoder s a
- interns :: Interns k -> k -> k
- internsFromMap :: Ord k => Map k a -> Interns k
- internsFromVMap :: Ord k => VMap VB kv k a -> Interns k
- toMemptyLens :: Monoid a => Lens' a b -> Lens' c b -> Lens' c a
- fromShareCBORfunctor :: ( FromCBOR (f b), Monad f) => Interns b -> Decoder s (f b)
Documentation
class Monoid ( Share a) => FromSharedCBOR a where Source #
getShare :: a -> Share a Source #
Whenever
fromShareCBOR
is being used for defining the instance this
function should return the state that can be added whenever user invokes
fromSharedPlusCBOR
.
mempty
is returned by default.
fromSharedCBOR :: Share a -> Decoder s a Source #
Utilize sharing when decoding, but do not add anything to the state for future sharing.
fromSharedPlusCBOR :: StateT ( Share a) ( Decoder s) a Source #
Deserialize with sharing and add to the state that is used for sharing. Default
implementation will add value returned by
getShare
for adding to the
state.
Instances
This is an abstract interface that does the interning. In other words it
does the actual sharing by looking up the supplied value in some existing
data structure and uses that value instead. Relying on this interface gives us
the benefit of ignoring the type of underlying data structure and allows us
to compose many
Intern
s with the monoidal interface provided by
Interns
wrapper. In order to create an
Intern
see the
internsFromMap
or
internsFromVMap
functions.
Intern | |
|
fromSharedLensCBOR :: FromSharedCBOR b => SimpleGetter bs ( Share b) -> StateT bs ( Decoder s) b Source #
fromSharedPlusLensCBOR :: FromSharedCBOR b => Lens' bs ( Share b) -> StateT bs ( Decoder s) b Source #
Just like
fromSharedPlusCBOR
, except allows to transform the shared state
with a lens.
fromNotSharedCBOR :: FromSharedCBOR a => Decoder s a Source #
Use
FromSharedCBOR
class while ignoring sharing
toMemptyLens :: Monoid a => Lens' a b -> Lens' c b -> Lens' c a Source #
Using this function it is possible to compose two lenses. One will extract a value and another will used it for placing it into a empty monoid. Here is an example of how a second element of a tuple can be projected on the third element of a 3-tuple.
toMemptyLens _3 _2 == lens (\(_, b) -> (mempty, mempty, b)) (\(a, _) (_, _, b) -> (a, b))
Here is an example where we extract a second element of a tuple and insert it at
third position of a three tuple while all other elements are set to
mempty
:
>>>
import Lens.Micro
>>>
("foo","bar") ^. toMemptyLens _3 _2 :: (Maybe String, (), String)
(Nothing,(),"bar")
In the opposite direction of extracting the third element of a 3-tuple and replacing the second element of the tuple the setter is being applied to
>>>
("foo","bar") & toMemptyLens _3 _2 .~ (Just "baz", (), "booyah") :: (String, String)
("foo","booyah")