checkRawCSV :: SFormat b -> CsvImport a -> CheckedCsvImport a
checkRawCSV format rh =
  if null missing then UnsafeCSV rh
  else error $ printf
       ("format '%s', version '%s': The configured header misses the following "
        ++ "fields required for Bayes or Description:\n%s")
       (fName format) (cVersion rh) $ unlines $ uncurry (printf "%s: %s") <$> missing
  where [head, bayes, desc] = S.fromList  . ($rh) <$>
          [cHeader, cBayes, mapMaybe toField . cDescription]
        missing =
          concatMap (uncurry zip <&> repeat *** (fmap T.unpack . toList . flip S.difference head))
                  [("cBayes", bayes), ("cDescription", desc)] :: [(String, String)]


-- * Pretty Printing
checkRawCSV :: SFormat b -> CsvImport a -> CheckedCsvImport a
checkRawCSV format rh =
  if null missing then UnsafeCSV rh
  else error $ printf
       ("format '%s', version '%s': The configured header misses the following "
        ++ "fields required for Bayes or Description:\n%s")
       (fName format) (cVersion rh) $ unlines $ uncurry (printf "%s: %s") <$> missing
  where [head, bayes, desc] = S.fromList  . ($rh) <$>
          [cHeader, cBayes, mapMaybe toField . cDescription]
        missing =
          concatMap (uncurry zip <&> repeat *** (fmap T.unpack . toList . flip S.difference head))
                  [("cBayes", bayes), ("cDescription", desc)] :: [(String, String)]


-- * Pretty Printing
checkRawCSV format rh =
  if null missing then UnsafeCSV rh
  else error $ printf
       ("format '%s', version '%s': The configured header misses the following "
        ++ "fields required for Bayes or Description:\n%s")
       (fName format) (cVersion rh) $ unlines $ uncurry (printf "%s: %s") <$> missing
  where [head, bayes, desc] = S.fromList  . ($rh) <$>
          [cHeader, cBayes, mapMaybe toField . cDescription]
        missing =
          concatMap (uncurry zip <&> repeat *** (fmap T.unpack . toList . flip S.difference head))
                  [("cBayes", bayes), ("cDescription", desc)] :: [(String, String)]


-- * Pretty Printing