metamon/transform

Named, deterministic input transformations. The name is surfaced in failure messages so a metamorphic relation always reports which transformation produced the follow-up input.

Types

A named, deterministic function a -> a.

name is shown in failure output. apply must be pure: same input, same output, no side effects.

pub type Transform(a) {
  Transform(name: String, apply: fn(a) -> a)
}

Constructors

  • Transform(name: String, apply: fn(a) -> a)

Values

pub fn constant(name: String, value: a) -> Transform(a)

A transform that ignores its input and always returns value. Use sparingly — most metamorphic relations want a real transformation rather than a constant.

pub fn identity() -> Transform(a)

The transform that returns its input unchanged.

pub fn new(name: String, apply: fn(a) -> a) -> Transform(a)

Construct a transform from a name and a function.

pub fn rename(t: Transform(a), name: String) -> Transform(a)

Override the name of a transform. The behaviour of apply is not changed — only the label that appears in failure reports.

pub fn repeat(t: Transform(a), times n: Int) -> Transform(a)

Apply t exactly n times. repeat(t, 0) is identity. Negative counts are treated as 0.

pub fn then(t1: Transform(a), t2: Transform(a)) -> Transform(a)

Sequential composition: then(t1, t2).apply(x) == t2.apply(t1.apply(x)). The composite name is "<t1.name> |> <t2.name>".

Search Document