diff options
author | Ben Sima <ben@bsima.me> | 2019-09-02 10:21:19 -0700 |
---|---|---|
committer | Ben Sima <ben@bsima.me> | 2019-09-02 10:21:19 -0700 |
commit | 970cb7089e001dd4025fc2351aa7873951f8a2c4 (patch) | |
tree | eeb46ff1a6a1419c776f383f0535780d76c8d25b /lore | |
parent | bb482a6d12500f826dbb43d6988cb84e59f7e4d2 (diff) |
[ibb] add keep instances
Diffstat (limited to 'lore')
-rw-r--r-- | lore/Biz/Ibb/Influencers.hs | 16 | ||||
-rw-r--r-- | lore/Biz/Ibb/Keep.hs | 56 |
2 files changed, 69 insertions, 3 deletions
diff --git a/lore/Biz/Ibb/Influencers.hs b/lore/Biz/Ibb/Influencers.hs index f00fe2e..a31eab4 100644 --- a/lore/Biz/Ibb/Influencers.hs +++ b/lore/Biz/Ibb/Influencers.hs @@ -1,19 +1,28 @@ {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE DeriveGeneric #-} +{-# LANGUAGE DeriveDataTypeable #-} + module Biz.Ibb.Influencers where import Data.Aeson -import Data.Text.Lazy (Text) +import Data.Text (Text) +import Data.Data (Data, Typeable) import GHC.Generics (Generic) data Person = Person { _name :: Text + -- ^ Their full name. , _pic :: Text + -- ^ A link to their picture. , _twitter :: Text + -- ^ Their twitter handle, without the `@` prefix. , _website :: Text + -- ^ Their main website, fully formed: `https://example.com` , _books :: [Book] + -- ^ A short list of the books they recommend. , _blurb :: Text - } deriving (Generic, Show, Eq) + -- ^ A short "about" section, like you would see on the jacket flap of a book. + } deriving (Generic, Show, Eq, Typeable, Data, Ord) instance FromJSON Person instance ToJSON Person @@ -22,7 +31,8 @@ data Book = Book { _title :: Text , _author :: Text , _amznref :: Text - } deriving (Generic, Show, Eq) + -- ^ Amazon REF number, for creating affiliate links. + } deriving (Generic, Show, Eq, Typeable, Data, Ord) instance FromJSON Book instance ToJSON Book diff --git a/lore/Biz/Ibb/Keep.hs b/lore/Biz/Ibb/Keep.hs new file mode 100644 index 0000000..348d0ad --- /dev/null +++ b/lore/Biz/Ibb/Keep.hs @@ -0,0 +1,56 @@ +{-# LANGUAGE TemplateHaskell #-} +{-# LANGUAGE GeneralizedNewtypeDeriving #-} +{-# LANGUAGE DeriveDataTypeable #-} +{-# LANGUAGE TypeFamilies #-} +{-# OPTIONS_GHC -fno-warn-orphans #-} + +-- | Keep is a database built on Data.Acid. +-- +-- If this proves useful, maybe we could make it a more general thing. Like +-- `Biz.Keep`. I could wrap all the safecopy stuff in my own template haskell +-- like `$(keep ''MyType)`. +-- +module Biz.Ibb.Keep where + +import Biz.Ibb.Influencers (Person(..), Book(..)) +import Data.SafeCopy +import Data.Data (Data, Typeable) +import Data.Text (Text) +import Data.IxSet (Indexable(..), ixFun, ixSet) + +-- * Index @Person@ + +$(deriveSafeCopy 0 'base ''Person) + +newtype PersonName = + PersonName Text deriving (Eq, Ord, Data, Typeable) + +newtype PersonBlurb = + PersonBlurb Text deriving (Eq, Ord, Data, Typeable) + +instance Indexable Person where + empty = ixSet + [ ixFun $ \p -> [ PersonName $ _name p ] + , ixFun $ \p -> [ _pic p ] + , ixFun $ \p -> [ _twitter p ] + , ixFun $ \p -> [ _website p ] + , ixFun $ \p -> [ _books p ] + , ixFun $ \p -> [ PersonBlurb $ _blurb p ] + ] + +-- * Index @Book@ + +$(deriveSafeCopy 0 'base ''Book) + +newtype BookTitle = + BookTitle Text deriving (Eq, Ord, Data, Typeable) + +newtype BookAuthor = + BookAuthor Text deriving (Eq, Ord, Data, Typeable) + +instance Indexable Book where + empty = ixSet + [ ixFun $ \b -> [ BookTitle $ _title b ] + , ixFun $ \b -> [ BookAuthor $ _author b ] + , ixFun $ \b -> [ _amznref b ] + ] |