<commit_before>import { Runtype, Rt, Static, create, ValidationError } from './base'
import { String as Str } from './string'

export interface Constraint<A extends Rt> extends Runtype<Static<A>> {
  tag: 'constraint'
  Underlying: A
}

export function Constraint<A extends Rt>(Underlying: A, constraint: (x: A) => boolean | string) {
  return create<Constraint<A>>(x => {
    const typed = Underlying.check(x)
    const result = constraint(typed)
    if (Str.guard(result))
      throw new ValidationError(result)
    else if (!result)
      throw new ValidationError('Failed constraint check')
    return typed<commit_msg>No need to rename this import<commit_after>import { Runtype, Rt, Static, create, ValidationError } from './base'
import { String } from './string'

export interface Constraint<A extends Rt> extends Runtype<Static<A>> {
  tag: 'constraint'
  Underlying: A
}

export function Constraint<A extends Rt>(Underlying: A, constraint: (x: A) => boolean | string) {
  return create<Constraint<A>>(x => {
    const typed = Underlying.check(x)
    const result = constraint(typed)
    if (String.guard(result))
      throw new ValidationError(result)
    else if (!result)
      throw new ValidationError('Failed constraint check')
    return typed
{'fraction_non_alphanumeric': 0.11746031746031746, 'fraction_numerical': 0.0, 'mean_word_length': 4.298319327731092, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 19, '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': '6924821', 'n_tokens_mistral': 373, 'n_tokens_neox': 363, 'n_words': 120}