Module
Data.Storage
- Package
- purescript-storable
- Repository
- GoNZooo/purescript-storable
#MonadStorage Source
class (Storable a) <= MonadStorage m a where
Members
store :: a -> m (Either StorageError Unit)
retrieve :: String -> m (Either StorageError a)
Reads a storable
a
when given a key in monadm
, returning either aLeft
containing an error representing unavailable storage, decoding error or no value matching the supplied' key.
Instances
(Storable a) => MonadStorage LocalStorage a
(Storable a) => MonadStorage SessionStorage a
(Storable a, MonadState (Map String String) m) => MonadStorage m a
#Storable Source
class Storable a where
Members
key :: a -> String
Produces a key from the given
a
. This is most appropriately anid
or something like it.prefix :: Proxy a -> String
When given a proxy of
a
returns a prefix that all items with that type will be stored with.serialize :: a -> String
Takes an
a
and (hopefully) reliably turns it into a string; this should be symmetric withdeserialize
. This can be conveniently implemented usingSimple.JSON
.deserialize :: String -> Either StorageError a
Takes a string and either successfully decodes it into a
Right a
or returns aDecodingError
that contains aNonEmptyList ForeignError
. This matches the error value thatSimple.JSON
returns.
Writes a storable
a
in a monadm
, returningLeft NoStorageError
representing the lack of a storage on error or returningRight Unit
on success.