type AlBhedIndex = IntMap IndexItem
newtype IndexItem = IndexItem (Primer, NonEmptyList Location)
$(makePrisms ''IndexItem)
IMap.empty
IMap.singleton (x ^. volume & fromVolume) (IndexItem (x, NonEmptyList.singleton y))
-- | Add a location to the primer in index
-- | If the primer is not in the index then we add the primer and location to the index
-- | Case 1: Primer volume is not in the Index, insert it as a new node
-- | Case 2: Primer exist so append location to primer locations
let vol = fromVolume $ primer ^. volume
f (IndexItem (p, ls)) (IndexItem (_, ls')) = IndexItem (p, NonEmptyList.merge ls ls')
in IMap.insertWith f vol (IndexItem (primer, NonEmptyList.singleton location)) map
-- | Get the primer from an index or Nothing if not found
index ^? traverse . _IndexItem . _1 . filtered (\(Primer vol' _ _) -> vol' == vol)
group
-- | Convert an AlBhed Index database to a prettyprinter `Doc` type
vsep . map (mod . indexItemToDoc) . IMap.elems
where
flatAlt
(primerToDoc primer <> line
<> align (indent 2 . vsep $ locationToDoc <$> NonEmptyList.toList locations))
(primerToDoc primer <> softline
<> list (locationToDoc <$> NonEmptyList.toList locations))
"Primer" <+> pretty (toRoman $ primer ^. volume) <+> squotes (pretty $ primer ^. alBhed)
<+> "->" <+> squotes (pretty $ primer ^. english)
(pretty . PrintableText.unPrintableText $ loc ^. area)
<> maybe emptyDoc ((" -" <+>) . pretty . PrintableText.unPrintableText) (loc ^. section)