readPolymerization :: Text -> (Polymer, Rules)
readPolymerization = either (error "Bad parse") (bimap T.unpack M.fromList)
  . parseOnly ((,) <$> template <*> (rules `sepBy1` "\n"))
 where
  template = takeTill isEndOfLine <* "\n\n"
  rules    = (,) <$> ((,) <$> letter <*> letter) <*> (" -> " *> letter)
readPolymerization :: Text -> (Polymer, Rules)
readPolymerization = either (error "Bad parse") (bimap T.unpack M.fromList)
  . parseOnly ((,) <$> template <*> (rules `sepBy1` "\n"))
 where
  template = takeTill isEndOfLine <* "\n\n"
  rules    = (,) <$> ((,) <$> letter <*> letter) <*> (" -> " *> letter)
readPolymerization = either (error "Bad parse") (bimap T.unpack M.fromList)
  . parseOnly ((,) <$> template <*> (rules `sepBy1` "\n"))
 where
  template = takeTill isEndOfLine <* "\n\n"
  rules    = (,) <$> ((,) <$> letter <*> letter) <*> (" -> " *> letter)