<commit_before>/**
 * A successful validation result.
 */
export type Success<A> = {
  /**
   * A tag indicating success.
   */
  success: true

  /**
   * The original value, cast to its validated type.
   */
  value: A
}

/**
 * A failed validation result.
 */
export type Failure = {
  /**
   * A tag indicating failure.
   */
  success: false

  /**
   * A message indicating the reason validation failed.
   */
  message: string
}

/**
 * The result of a type validation.
 */
export type Result<A> = Success<A> | Failure

/**
 * A runtype determines at runtime whether a value conforms to a type specification.
 */
export type Runtype<A> = {
  /**
   * Attempts to cast a value to the type for this runtype and return it.
   * Throws an exception if validation fails.
   */
  coerce(x: {}): A

  /**
   * Validates that a value conforms to this type, and returns a result indicating
   * success or failure (does not throw).
   */
  validate(x: {}): Result<A>

  /**
   * A type guard for this runtype.
   */
  guard(x: {}): x is A

  /**
   * Provides a way to reference the constructed type that this runtype
   * validates. Note that this is a false witness; it's always undefined.
   */
  witness: A
}

/**
 * Validates anything, but provides no new type information about it.
 */
export const Anything: Runtype<{}> = runtype(x => x)

/**
 * Validates nothing (always fails).
 */
export const Nothing: Runtype<never> = runtype(x => {
  throw new ValidationError('Expected nothing but got something')
})

/**
 * Validates that a value is undefined.
 */
export const Undefined: Runtype<undefined> = runtype(x => {
  if (x !== undefined)
    throw new ValidationError(`Expected undefined but was ${typeof x}`)
  return x
})

/**
 * Validates that a value is null.<commit_msg>The validator really needs to take any (not {}) to account for null and undefined<commit_after>
/**
 * A successful validation result.
 */
export type Success<A> = {
  /**
   * A tag indicating success.
   */
  success: true

  /**
   * The original value, cast to its validated type.
   */
  value: A
}

/**
 * A failed validation result.
 */
export type Failure = {
  /**
   * A tag indicating failure.
   */
  success: false

  /**
   * A message indicating the reason validation failed.
   */
  message: string
}

/**
 * The result of a type validation.
 */
export type Result<A> = Success<A> | Failure

/**
 * A runtype determines at runtime whether a value conforms to a type specification.
 */
export type Runtype<A> = {
  /**
   * Attempts to cast a value to the type for this runtype and return it.
   * Throws an exception if validation fails.
   */
  coerce(x: any): A

  /**
   * Validates that a value conforms to this type, and returns a result indicating
   * success or failure (does not throw).
   */
  validate(x: any): Result<A>

  /**
   * A type guard for this runtype.
   */
  guard(x: any): x is A

  /**
   * Provides a way to reference the constructed type that this runtype
   * validates. Note that this is a false witness; it's always undefined.
   */
  witness: A
}

/**
 * Validates anything, but provides no new type information about it.
 */
export const Anything: Runtype<{}> = runtype(x => x)

/**
 * Validates nothing (always fails).
 */
export const Nothing: Runtype<never> = runtype(x => {
  throw new ValidationError('Expected nothing but got something')
})

/**
 * Validates that a value is undefined.
 */
export const Undefined: Runtype<undefined> = runtype(x => {
  if (x !== undefined)
    throw new ValidationError(`Expected undefined but was ${typeof x}`)
  return x
})

/**
 * Validates that a value is null.
{'fraction_non_alphanumeric': 0.11887727022564668, 'fraction_numerical': 0.0, 'mean_word_length': 2.8835470085470085, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 25, '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': '1915263', 'n_tokens_mistral': 1095, 'n_tokens_neox': 1067, 'n_words': 439}