41 lines
913 B
Haskell
41 lines
913 B
Haskell
module Data.Entry where
|
|
import Data.ByteString.Lazy (ByteString)
|
|
import Data.Set (Set)
|
|
import Data.Text (Text)
|
|
import Control.Lens
|
|
|
|
newtype URL = URL String
|
|
deriving (Show)
|
|
newtype Tag = Tag Text
|
|
deriving (Show, Eq, Ord)
|
|
|
|
data Entry = Entry
|
|
{ entryURL :: URL
|
|
, entryTitle :: Text
|
|
, entryContent :: ByteString
|
|
, entryScore :: Int
|
|
, entryTags :: Set Tag
|
|
}
|
|
deriving Show
|
|
|
|
-- * Lenses for accessing relevant parts of entry
|
|
|
|
_URL :: Iso' URL String
|
|
_URL = iso (\(URL u) -> u) URL
|
|
|
|
content :: Lens' Entry ByteString
|
|
content = lens entryContent (\ en bs -> en{entryContent=bs})
|
|
|
|
title :: Lens' Entry Text
|
|
title = lens entryTitle (\ en txt -> en{entryTitle=txt})
|
|
|
|
url :: Lens' Entry URL
|
|
url = lens entryURL (\ en u -> en{entryURL = u})
|
|
|
|
score :: Lens' Entry Int
|
|
score = lens entryScore (\ en n -> en{entryScore=n})
|
|
|
|
tags :: Lens' Entry (Set Tag)
|
|
tags = lens entryTags (\ en txts -> en{entryTags=txts})
|
|
|