Entity / foldkit-entity

Law

namespace · packages/entity/src/law.ts:79

const Law = {
  associative,
  commutative,
  idempotent,
  preservesCollation,
  identity,
  absorbing,
  inverse,
  distributes,
  monotonic,
  within,
  $match,
  witnessesNamed,
  describe,
}

Its type

type Law = Data.TaggedEnum<{
  Associative: {
    readonly domain: Option.Option<Schema.Top>
  }
  Commutative: {
    readonly domain: Option.Option<Schema.Top>
  }
  Idempotent: {
    readonly domain: Option.Option<Schema.Top>
  }
  Identity: {
    readonly domain: Option.Option<Schema.Top>
    readonly value: unknown
    readonly side: Side
  }
  Absorbing: {
    readonly domain: Option.Option<Schema.Top>
    readonly value: unknown
    readonly side: Side
  }
  Inverse: {
    readonly domain: Option.Option<Schema.Top>
    readonly other: AnyOperator
    readonly identity: unknown
  }
  Distributes: {
    readonly domain: Option.Option<Schema.Top>
    readonly over: AnyOperator
  }
  Monotonic: {
    readonly domain: Option.Option<Schema.Top>
    readonly direction: 'increasing' | 'decreasing'
    readonly position: number
  }
  PreservesCollation: {
    readonly domain: Option.Option<Schema.Top>
  }
}>

A law, over its domain: by default every non-null value of the operator's input schemas; narrowed by Law.within.

In the guides

Members

Law.associative

const · packages/entity/src/law.ts:80

associative: {
  readonly _tag: 'Associative'
  readonly domain: Option.Option<Schema.Top>
}

Law.commutative

const · packages/entity/src/law.ts:81

commutative: {
  readonly _tag: 'Commutative'
  readonly domain: Option.Option<Schema.Top>
}

Law.idempotent

const · packages/entity/src/law.ts:82

idempotent: {
  readonly _tag: 'Idempotent'
  readonly domain: Option.Option<Schema.Top>
}

Law.preservesCollation

const · packages/entity/src/law.ts:83

preservesCollation: {
  readonly _tag: 'PreservesCollation'
  readonly domain: Option.Option<Schema.Top>
}

Law.identity

function · packages/entity/src/law.ts:85

identity(value: unknown, side?: Side): Law

value leaves the other argument as it is, from side (both by default).

Law.absorbing

function · packages/entity/src/law.ts:88

absorbing(value: unknown, side?: Side): Law

value is the answer whatever the other argument, from side (both by default).

Law.inverse

function · packages/entity/src/law.ts:91

inverse<In extends ReadonlyArray<Schema.Top>, Out extends Schema.Top>(
  other: Operator<In, Out>,
  identity: unknown,
): Law

other undoes the operator: op(a, other(a)) is identity.

Law.distributes

function · packages/entity/src/law.ts:96

distributes<In extends ReadonlyArray<Schema.Top>, Out extends Schema.Top>(
  over: Operator<In, Out>,
): Law

The operator distributes over over, from the left.

Law.monotonic

function · packages/entity/src/law.ts:100

monotonic(direction: 'increasing' | 'decreasing', position: number): Law

Moving the argument at position up moves the result up (or down, decreasing).

Law.within

function · packages/entity/src/law.ts:107

within(law: Law, domain: Schema.Top): Law

The law over the values domain accepts only: a law that holds of the integers and not of every number, say, narrowed so it is tested where it is claimed.

Law.$match

const · packages/entity/src/law.ts:110

$match: { <Cases extends { readonly Associative: (args: { readonly _tag: "Associative"; readonly domain: Option.Option<Schema.Top>; }) => any; readonly Commutative: (args: { readonly _tag: "Commutative"; readonly domain: Option.Option<Schema.Top>; }) => any; readonly Idempotent: (args: { readonly _tag: "Idempotent"; readonly domain: Option.Option<Schema.Top>; }) => any; readonly Identity: (args: { readonly _tag: "Identity"; readonly domain: Option.Option<Schema.Top>; readonly value: unknown; readonly side: Side; }) => any; readonly Absorbing: (args: { readonly _tag: "Absorbing"; readonly domain: Option.Option<Schema.Top>; readonly value: unknown; readonly side: Side; }) => any; readonly Inverse: (args: { readonly _tag: "Inverse"; readonly domain: Option.Option<Schema.Top>; readonly other: AnyOperator; readonly identity: unknown; }) => any; readonly Distributes: (args: { readonly _tag: "Distributes"; readonly domain: Option.Option<Schema.Top>; readonly over: AnyOperator; }) => any; readonly Monotonic: (args: { readonly _tag: "Monotonic"; readonly domain: Option.Option<Schema.Top>; readonly direction: "increasing" | "decreasing"; readonly position: number; }) => any; readonly PreservesCollation: (args: { readonly _tag: "PreservesCollation"; readonly domain: Option.Option<Schema.Top>; }) => any; }>(cases: Cases): (value: { readonly _tag: "Associative"; readonly domain: Option.Option<Schema.Top>; } | { readonly _tag: "Commutative"; readonly domain: Option.Option<Schema.Top>; } | { readon …;

Law.witnessesNamed

function · packages/entity/src/law.ts:117

witnessesNamed(law: LawDescription): ReadonlyArray<string>

The operators a law, as JSON, calls besides its own (inverse's and distributes' witnesses), by name: evidence of it is of their implementations too, and goes when one of them is replaced.

Law.describe

function · packages/entity/src/law.ts:123

describe(law: Law): LawDescription

The law as JSON: its kind, its witnesses (operators by name) and its domain's JSON Schema.