#MonadStorage Source

class (Storable a) <= MonadStorage m a  where


  • store :: a -> m (Either StorageError Unit)

    Writes a storable a in a monad m, returning Left NoStorageError representing the lack of a storage on error or returning Right Unit on success.

  • retrieve :: String -> m (Either StorageError a)

    Reads a storable a when given a key in monad m, returning either a Left containing an error representing unavailable storage, decoding error or no value matching the supplied' key.


#Storable Source

class Storable a  where


  • key :: a -> String

    Produces a key from the given a. This is most appropriately an id 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 with deserialize. This can be conveniently implemented using Simple.JSON.

  • deserialize :: String -> Either StorageError a

    Takes a string and either successfully decodes it into a Right a or returns a DecodingError that contains a NonEmptyList ForeignError. This matches the error value that Simple.JSON returns.

#getKey Source

getKey :: forall a. Storable a => a -> String

Given a storable a will produce the key that it would have in storage.

#makeKey Source

makeKey :: forall a. Storable a => Proxy a -> String -> String

When given a Proxy a and a key will produce the corresponding composite key.