nim_iterator_stream_experiment/optics/lenslaws

Utilities to check if a lens verifies the lens laws.

This module is meant to be used in test suites.

Examples

Types

IdentitySpec[S] = tuple[expected: S]
Parameters for the lens identity law.   Source Edit
RetentionSpec[S; T] = tuple[input: S, expected: T]
Parameters for the lens retention law.   Source Edit
DoubleWriteSpec[S; T] = tuple[input: S, first: T, second: T]
Parameters for the lens double write law.   Source Edit
LensLawsSpec[S; T] = tuple[identity: IdentitySpec[S], retention: RetentionSpec[S, T],
                        doubleWrite: DoubleWriteSpec[S, T]]
  Source Edit

Funcs

func identitySpec[S](expected: S): IdentitySpec[S]
  Source Edit
func retentionSpec[S; T](input: S; expected: T): RetentionSpec[S, T]
  Source Edit
func doubleWriteSpec[S; T](input: S; first: T; second: T): DoubleWriteSpec[S, T]
  Source Edit
func lensLawsSpec[S; T](identity: IdentitySpec[S]; retention: RetentionSpec[S, T];
                      doubleWrite: DoubleWriteSpec[S, T]): LensLawsSpec[S, T]
  Source Edit

Templates

template checkIdentityLaw[S; T](lens: Lens[S, T]; spec: IdentitySpec[S]): bool
Checks whether a read followed by a write through lens is the same as not modifying the initial structure.   Source Edit
template checkRetentionLaw[S; T](lens: Lens[S, T]; spec: RetentionSpec[S, T]): bool
Checks whether a write followed by a read through lens returns the same value written.   Source Edit
template checkDoubleWriteLaw[S; T](lens: Lens[S, T]; spec: DoubleWriteSpec[S, T]): bool
Checks whether two consecutive writes through lens is the same as directly writing the second value.   Source Edit
template checkLensLaws[S; T](lens: Lens[S, T]; spec: LensLawsSpec[S, T]): bool
  Source Edit