<commit_before>import { Boolean, Number, String, Literal, Array, Tuple, Record, Union, Static } from '../src/index'

const Vector = Tuple(Number, Number, Number)
type Vector = Static<typeof Vector>

const Asteroid = Record({
  type: Literal('asteroid'),
  location: Vector,
  mass: Number,
})
type Asteroid = Static<typeof Asteroid>

const Planet = Record({
  type: Literal('planet'),
  location: Vector,
  mass: Number,
  population: Number,
  habitable: Boolean,
})
type Planet = Static<typeof Planet>

const Rank = Union(
  Literal('captain'),
  Literal('first mate'),
  Literal('officer'),
  Literal('ensign'),
)
type Rank = Static<typeof Rank>

const CrewMember = Record({
  name: String,
  age: Number,
  rank: Rank,
  home: Planet,
})
type CrewMember = Static<typeof CrewMember>

const Ship = Record({
  type: Literal('ship'),
  location: Vector,
  mass: Number,
  name: String,
  crew: Array(CrewMember),
})
type Ship = Static<typeof Ship>

const SpaceObject = Union(Asteroid, Planet, Ship)
type SpaceObject = Static<typeof SpaceObject><commit_msg>Add a constraint to the example<commit_after>import { Boolean, Number, String, Literal, Array, Tuple, Record, Union, Static } from '../src/index'

const NonNegative = Number.withConstraint(n => n >= 0)

const Vector = Tuple(Number, Number, Number)
type Vector = Static<typeof Vector>

const Asteroid = Record({
  type: Literal('asteroid'),
  location: Vector,
  mass: NonNegative,
})
type Asteroid = Static<typeof Asteroid>

const Planet = Record({
  type: Literal('planet'),
  location: Vector,
  mass: NonNegative,
  population: NonNegative,
  habitable: Boolean,
})
type Planet = Static<typeof Planet>

const Rank = Union(
  Literal('captain'),
  Literal('first mate'),
  Literal('officer'),
  Literal('ensign'),
)
type Rank = Static<typeof Rank>

const CrewMember = Record({
  name: String,
  age: NonNegative,
  rank: Rank,
  home: Planet,
})
type CrewMember = Static<typeof CrewMember>

const Ship = Record({
  type: Literal('ship'),
  location: Vector,
  mass: NonNegative,
  name: String,
  crew: Array(CrewMember),
})
type Ship = Static<typeof Ship>

const SpaceObject = Union(Asteroid, Planet, Ship)
type SpaceObject = Static<typeof SpaceObject>
{'fraction_non_alphanumeric': 0.13116236996834013, 'fraction_numerical': 0.0004522840343735866, 'mean_word_length': 4.978378378378379, 'pattern_counts': {'":': 0, '<': 17, '<?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': '7280964', 'n_tokens_mistral': 738, 'n_tokens_neox': 684, 'n_words': 217}