<commit_before>import Text.JSON.AttoJSON
import qualified Data.ByteString as S

main :: IO ()
main = S.putStr . showJSON . jsonConcat . either err id . parseJSON =<< S.getContents
  where jsonConcat (JSArray a)  = JSArray (concatMap unJSArray a)
        jsonConcat (JSObject _) = error "unexpected non-JSON array"
        jsonConcat _            = error "impossible by decodeStrict post-condition"
        unJSArray (JSArray a)   = a
        unJSArray _             = error "unexpected non-JSON array"
        err s                   = error $ "JSON decoding: " ++ s
<commit_msg>json-concat: Add a usage message and prints a newline at the end<commit_after>import Text.JSON.AttoJSON
import qualified Data.ByteString as S
import Control.Monad (when)
import System.IO (hPutStrLn, stderr)
import System.Exit (exitFailure)
import System.Environment (getArgs)

usage :: IO a
usage = mapM_ (hPutStrLn stderr)
  ["Usage: json-concat [--help]"
  ,""
  ,"Reads the standard input as a JSON array of arrays, and writes"
  ,"on standard output the concatenations of these arrays as a JSON array."]
  >> exitFailure

main :: IO ()
main = do args <- getArgs
          when (not . null $ args) usage
          S.putStrLn . showJSON . jsonConcat . either err id . parseJSON
            =<< S.getContents
  where jsonConcat (JSArray a)  = JSArray (concatMap unJSArray a)
        jsonConcat (JSObject _) = error "unexpected non-JSON array"
        jsonConcat _            = error "not a JSON document (neither array, nor object)"
        unJSArray (JSArray a)   = a
        unJSArray _             = error "unexpected non-JSON array"
        err s                   = error $ "JSON decoding: " ++ s

{'fraction_non_alphanumeric': 0.08858501783590964, 'fraction_numerical': 0.0, 'mean_word_length': 2.5357142857142856, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5781229', 'n_tokens_mistral': 500, 'n_tokens_neox': 493, 'n_words': 177}