import { Do, Effect, Kind1 } from './effect' import { Throw, Try } from './exception' import { Equals } from './util' /** * Assert a boolean expression is true * * @typeParam _B - The boolean value to assert * * @throws {"assertion error"} if false * * @example * Here's an example checking if `SomeValue` is not equal to [1,2,3] * Uses - {@link util.Not}, {@link util.Equals} * * ```ts * Assert>> * ``` */ export interface Assert<_B extends boolean> extends Effect {} /** * Create a test block * * @typeParam _M - description of the test * @typeParam _Effs - List of effects to evaluate * * @example * ```ts * type main = [ * Test<"should check if result is 21", [ * Bind, () => AssertEquals>, * // equivalent to... * Bind, AssertEqualsK<21>>, * ]> * ] * ``` */ export interface Test<_M extends string, _Effs extends Effect[]> extends Effect {} export interface ShowAssertionError<_L extends unknown, _R extends unknown> extends Effect {} /** * Assert if left and right values are equal structurally * * @typeParam _Left - Left value * @typeParam _Right - Right value * * @example * ```ts * type main = [ * AssertEquals<`Foo ${'bar'}`, 'Foo bar'> * AssertEquals<[2, ...[3, 4]], [2, 3, 4]> * ] * ``` */ export type AssertEquals = Try< Assert>, () => Do<[ShowAssertionError, Throw]> > /** * An alternate point-free api for {@link AssertEquals} * * @typeParam _Right - Right value * * @example * ```ts * type main = [ * Bind, AssertEqualsK<63>> * ] * ``` */ export interface AssertEqualsK extends Kind1 { return: AssertEquals }