<commit_before>package com.ephox.argonaut

sealed trait Json {
  import Json._

  def fold[X](
    jsonNull: => X,
    jsonBool: Boolean => X,
    jsonNumber: JsonNumber => X,
    jsonString: String => X,
    jsonArray: JsonArray => X,
    jsonObject: JsonObject => X
  ): X

  def ifNull[X](t: => X, f: => X) =
    fold(t,
         _ => f,
         _ => f,
         _ => f,
         _ => f,
         _ => f)

  def ifBool[X](t: Boolean => X, f: => X) =
    fold(f,
         t(_),
         _ => f,
         _ => f,
         _ => f,
         _ => f)

  def ifNumber[X](t: JsonNumber => X, f: => X) =
    fold(f,
         _ => f,
         t(_),
         _ => f,
         _ => f,
         _ => f)

  def ifString[X](t: String => X, f: => X) =
    fold(f,
         _ => f,
         _ => f,
         t(_),
         _ => f,
         _ => f)

  def ifArray[X](t: JsonArray => X, f: => X) =
    fold(f,
         _ => f,
         _ => f,
         _ => f,
         t(_),
         _ => f)

  def ifObject[X](t: JsonObject => X, f: => X) =
    fold(f,
         _ => f,
         _ => f,
         _ => f,
         _ => f,
         t(_))

  def isNull =
    ifNull(true, false)

  def isBool =
    ifBool(_ => true, false)

  def isNumber =
    ifNumber(_ => true, false)

  def isString =
    ifString(_ => true, false)

  def isArray =
    ifArray(_ => true, false)

  def isObject =
    ifObject(_ => true, false)

  def ifBoolTrue[X](t: => X, f: => X) =
    ifBool(x => if(x) t else f, f)

  def ifBoolFalse[X](t: => X, f: => X) =
    ifBool(x => if(x) f else t, f)

  def number =
    ifNumber(Some(_), None)

  def numberOr(d: => JsonNumber) =
    number getOrElse d

  def numberOrZero =
    numberOr(0D)

  def string =
    ifString(Some(_), None)

  def stringOr(s: => String) =
    string getOrElse s

  def stringOrEmpty =
    stringOr("")

  def array =
    ifArray(Some(_), None)

  def arrayOr(a: => JsonArray) =
    array getOrElse a

  def arrayOrEmpty =
    arrayOr(Nil)

  def objectt =
    ifObject(Some(_), None)

  def objectOr(o: => JsonObject) =
    objectt getOrElse o

  def objectOrEmpty =
    objectOr(Nil)
  
  lazy val objectMap: Option[JsonObjectMap] =
    fold(None,
         _ => None,
         _ => None,
         _ => None,
         _ => None,
         x => Some(x.toMap))

  def objectMapOr(m: => JsonObjectMap) =
    objectMap getOrElse m

  def objectMapOrEmpty =
    objectMapOr(Map.empty)

  def objectValue(k: String): Option[Json] =
    objectMap flatMap (_ get k)

  def objectValueOr(k: String, v: => Json) =
    objectValue(k) getOrElse v

  def not =
    ifBool(x => jsonBool(!x), this)

  def withNumber(f: JsonNumber => JsonNumber) =
    ifNumber(jsonNumber compose f, this)

  def withArray(f: JsonArray => JsonArray) =
    ifArray(jsonArray compose f, this)

  def withObject(f: JsonObject => JsonObject) =
    ifObject(jsonObject compose f, this)

  def objectKeys =
    ifObject(_ map (_._1), Nil)

  def objectValue =
    ifObject(_ map (_._2), Nil)

  def ->:(obj: (String, Json)) =
    jsonObject(ifObject(obj :: _, List(obj)))

  def -->>:(ar: Json) =
    jsonArray(ifArray(ar :: _, List(ar)))

  def =>:(obj: (String, Json)) =
    withObject(obj :: _)

  def ==>>:(ar: Json) =
    withArray(ar :: _)<commit_msg>documentation<commit_after>package com.ephox.argonaut

sealed trait Json {
  import Json._

  def fold[X](
    jsonNull: => X,
    jsonBool: Boolean => X,
    jsonNumber: JsonNumber => X,
    jsonString: String => X,
    jsonArray: JsonArray => X,
    jsonObject: JsonObject => X
  ): X

  def ifNull[X](t: => X, f: => X) =
    fold(t,
         _ => f,
         _ => f,
         _ => f,
         _ => f,
         _ => f)

  def ifBool[X](t: Boolean => X, f: => X) =
    fold(f,
         t(_),
         _ => f,
         _ => f,
         _ => f,
         _ => f)

  def ifNumber[X](t: JsonNumber => X, f: => X) =
    fold(f,
         _ => f,
         t(_),
         _ => f,
         _ => f,
         _ => f)

  def ifString[X](t: String => X, f: => X) =
    fold(f,
         _ => f,
         _ => f,
         t(_),
         _ => f,
         _ => f)

  def ifArray[X](t: JsonArray => X, f: => X) =
    fold(f,
         _ => f,
         _ => f,
         _ => f,
         t(_),
         _ => f)

  def ifObject[X](t: JsonObject => X, f: => X) =
    fold(f,
         _ => f,
         _ => f,
         _ => f,
         _ => f,
         t(_))

  def isNull =
    ifNull(true, false)

  def isBool =
    ifBool(_ => true, false)

  def isNumber =
    ifNumber(_ => true, false)

  def isString =
    ifString(_ => true, false)

  def isArray =
    ifArray(_ => true, false)

  def isObject =
    ifObject(_ => true, false)

  def ifBoolTrue[X](t: => X, f: => X) =
    ifBool(x => if(x) t else f, f)

  def ifBoolFalse[X](t: => X, f: => X) =
    ifBool(x => if(x) f else t, f)

  def number =
    ifNumber(Some(_), None)

  def numberOr(d: => JsonNumber) =
    number getOrElse d

  def numberOrZero =
    numberOr(0D)

  def string =
    ifString(Some(_), None)

  def stringOr(s: => String) =
    string getOrElse s

  def stringOrEmpty =
    stringOr("")

  def array =
    ifArray(Some(_), None)

  def arrayOr(a: => JsonArray) =
    array getOrElse a

  def arrayOrEmpty =
    arrayOr(Nil)

  def objectt =
    ifObject(Some(_), None)

  def objectOr(o: => JsonObject) =
    objectt getOrElse o

  def objectOrEmpty =
    objectOr(Nil)
  
  lazy val objectMap: Option[JsonObjectMap] =
    fold(None,
         _ => None,
         _ => None,
         _ => None,
         _ => None,
         x => Some(x.toMap))

  def objectMapOr(m: => JsonObjectMap) =
    objectMap getOrElse m

  def objectMapOrEmpty =
    objectMapOr(Map.empty)

  def objectValue(k: String): Option[Json] =
    objectMap flatMap (_ get k)

  def objectValueOr(k: String, v: => Json) =
    objectValue(k) getOrElse v

  def not =
    ifBool(x => jsonBool(!x), this)

  def withNumber(f: JsonNumber => JsonNumber) =
    ifNumber(jsonNumber compose f, this)

  def withArray(f: JsonArray => JsonArray) =
    ifArray(jsonArray compose f, this)

  def withObject(f: JsonObject => JsonObject) =
    ifObject(jsonObject compose f, this)

  def objectKeys =
    ifObject(_ map (_._1), Nil)

  def objectValue =
    ifObject(_ map (_._2), Nil)

  /**
   * If this is a JSON object, then prepend the given value, otherwise, return a JSON object with only the given value.
   */
  def ->:(obj: (String, Json)) =
    jsonObject(ifObject(obj :: _, List(obj)))

  /**
   * If this is a JSON array, then prepend the given value, otherwise, return a JSON array with only the given value.
   */
  def -->>:(ar: Json) =
    jsonArray(ifArray(ar :: _, List(ar)))

  /**
   * If this is a JSON object, then prepend the given value, otherwise, return this.
   */
  def =>:(obj: (String, Json)) =
    withObject(obj :: _)

  /**
   * If this is a JSON array, then prepend the given value, otherwise, return this.
   */
  def ==>>:(ar: Json) =
    withArray(ar :: _)
{'fraction_non_alphanumeric': 0.15232073573789337, 'fraction_numerical': 0.0008621928437993965, 'mean_word_length': 2.0090791180285343, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 153, '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': '5098173', 'n_tokens_mistral': 2594, 'n_tokens_neox': 2481, 'n_words': 666}