Skip to content

assertcheck v1.0.0


assertcheck / assert / homomorphic

Function: homomorphic()

ts
function homomorphic<T>(
   fn, 
   combine, 
   a, 
   b, 
   opts?): void;

Defined in: src/assert.ts:1893

Asserts that fn(combine(a, b)) equals combine(fn(a), fn(b)). Tests the homomorphism law — that a transform distributes over a combining operation.

Type Parameters

Type Parameter
T

Parameters

ParameterType
fn(v) => T
combine(a, b) => T
aT
bT
opts?Opts

Returns

void

Example

ts
assert.homomorphic(
  normalize,
  (a, b) => [...a, ...b],
  [1, 2], [3, 4],
  "normalize must distribute over concatenation"
)

Released under the Apache 2.0 License. Built by Vagabond Studio — senior-only for growing companies.