Curried lazys

master
Freywar Ulvnaudgari 2 years ago
parent 531c52212d
commit 981b032972
  1. 28
      src/bool.ts
  2. 14
      src/core.ts
  3. 50
      src/list.ts
  4. 30
      src/num.ts
  5. 34
      test/bool.spec.ts
  6. 8
      test/core.spec.ts
  7. 123
      test/list.spec.ts
  8. 38
      test/num.spec.ts
  9. 35
      test/util.ts

@ -1,30 +1,30 @@
import { Lazy, V, _ } from './core'; import { Lazy, Q, V, _ } from './core';
export type Bool = Lazy<<T extends V>(t: T) => (f: T) => T>; export type Bool = Lazy<<T extends V>(t: T) => Lazy<(f: T) => T>>;
export const True: Bool export const True: Bool
= _(t => _ => t) as Bool; = _(t => _(_f => t)) as Bool;
export const False: Bool export const False: Bool
= _(_ => f => f); = _(_t => _(f => f));
export const iif: <T extends V>(b: Bool) => (t: T) => (f: T) => T export const iif: <T extends V>(b: Bool) => Lazy<(t: T) => Lazy<(f: T) => T>>
= b => t => f => b.then(b => b(t)(f)); = b => _(t => _(f => b.then(b => b(t).then(e=>e(f)))));
export const not: (b: Bool) => Bool export const not: (b: Bool) => Bool
= b => b.then(b => b(False)(True)); = b => b.then(b => b(False).then(e=>e(True)));
export const and: (l: Bool) => (r: Bool) => Bool export const and: (l: Bool) => Lazy<(r: Bool) => Bool>
= l => r => l.then(l => l(r)(False)); = l => _(r => l.then(l => l(r).then(e=>e(False))));
export const or: (l: Bool) => (r: Bool) => Bool export const or: (l: Bool) => Lazy<(r: Bool) => Bool>
= l => r => l.then(l => l(True)(r)); = l => _(r => l.then(l => l(True).then(e=>e(r))));
export const xor: (l: Bool) => (r: Bool) => Bool export const xor: (l: Bool) => Lazy<(r: Bool) => Bool>
= l => r => l.then(l => l(not(r))(r)); = l => _(r => l.then(l => l(not(r)).then(e=>e(r))));
export const fromBoolean: (b: boolean) => Bool export const fromBoolean: (b: boolean) => Bool
= b => b ? True : False; = b => b ? True : False;
export const toBoolean: (b: Bool) => boolean export const toBoolean: (b: Bool) => boolean
= b => b.then(b => b(_(true))(_(false))).value; = b => b.then(b => b(_(true as unknown as Q)).then(e=>e(_(false as unknown as Q)))).value as unknown as boolean;

@ -1,4 +1,4 @@
export class Lazy<T> { export class Lazy<T extends (v: unknown) => Lazy<any>> {
protected _value?: T; protected _value?: T;
constructor(private _eval: () => T) { } constructor(private _eval: () => T) { }
@ -18,10 +18,12 @@ export class Lazy<T> {
} }
} }
export type V = Lazy<unknown>; export type Q = (v: unknown) => Lazy<any>;
export const _ = <T>(v: T): Lazy<T> => new Lazy(() => v); export type V = Lazy<(v: unknown) => Lazy<any>>;
export const $ = <T>(v: Lazy<T>): T => v.value;
export const _ = <T extends (v: unknown) => Lazy<any>>(v: T): Lazy<T> => new Lazy(() => v);
export const $ = <T extends (v: unknown) => Lazy<any>>(v: Lazy<T>): T => v.value;
export const undef: any = new Lazy(() => { export const undef: any = new Lazy(() => {
throw new Error('undefined'); throw new Error('undefined');
@ -29,5 +31,5 @@ export const undef: any = new Lazy(() => {
export const id: <T extends V>(v: T) => T export const id: <T extends V>(v: T) => T
= v => v; = v => v;
export const cnst: <T extends V> (v: T) => (_: unknown) => T export const cnst: <T extends V> (v: T) => Lazy<(_: unknown) => T>
= v => _ => v; = v => _(_ => v);

@ -1,50 +1,50 @@
import { Lazy, V, _, cnst, id, undef } from './core'; import { Lazy, Q, V, _, undef } from './core';
import { fromNumber, Num, toNumber } from './num'; import { fromNumber, Num, toNumber } from './num';
import { Bool, iif } from './bool'; import { Bool, iif } from './bool';
export type List<T extends V> = Lazy<<R extends V>(z: R) => (f: (x: T) => (xs: List<T>) => R) => R>; export type List<T extends V> = Lazy<<R extends V>(z: R) => Lazy<(f: (x: T) => Lazy<(xs: List<T>) => R>) => R>>;
export const Nil: List<any> export const Nil: List<any>
= _(z => _ => z) as List<any>; = _(z => _(_f => z)) as List<any>;
export const Cons: <T extends V>(x: T) => (xs: List<T>) => List<T> export const Cons: <T extends V>(x: T) => Lazy<(xs: List<T>) => List<T>>
= <T extends V>(x: T) => (xs: List<T>) => _(_ => f => f(x)(xs)) as List<T>; = <T extends V>(x: T) => _((xs: List<T>) => _(_z => _(f => f(x).then(e=>e(xs)))) as List<T>);
export const cons: <T extends V>(x: T) => (xs: List<T>) => List<T> export const cons: <T extends V>(x: T) => Lazy<(xs: List<T>) => List<T>>
= Cons; = Cons;
export const head: <T extends V>(xs: List<T>) => T export const head: <T extends V>(xs: List<T>) => T
= xs => xs.then(xs => xs(undef)(cnst)); = xs => xs.then(xs => xs(undef).then(e=>e(x=>_(_xs=>x))));
export const tail: <T extends V>(xs: List<T>) => List<T> export const tail: <T extends V>(xs: List<T>) => List<T>
= xs => xs.then(xs => xs(undef)(_ => id)); = xs => xs.then(xs => xs(undef).then(e=>e(_x =>_(xs=>xs))));
export const foldl: <T extends V, R extends V>(f: (a: R) => (x: T) => R) => (z: R) => (xs: List<T>) => R export const foldl: <T extends V, R extends V>(f: (a: R) => Lazy<(x: T) => R>) => Lazy<(z: R) => Lazy<(xs: List<T>) => R>>
= f => z => xs => xs.then(xs => xs(z)(x => xs => foldl(f)(f(z)(x))(xs))); = f => _(z => _(xs => xs.then(xs => xs(z).then(e=>e(x => _(xs => foldl(f).then(e=>e(f(z).then(e=>e(x))).then(e=>e(xs)))))))));
export const foldlz: <T extends V>(f: (a: T) => (x: T) => T) => (xs: List<T>) => T export const foldlz: <T extends V>(f: (a: T) => Lazy<(x: T) => T>) => Lazy<(xs: List<T>) => T>
= f => xs => xs.then(xs => xs(undef)(foldl(f))); = f => _(xs => xs.then(xs => xs(undef).then(e=>e(x=>_(xs=>foldl(f).then(e=>e(x).then(e=>e(xs))))))));
export const foldr: <T extends V, R extends V>(f: (x: T) => (a: R) => R) => (z: R) => (xs: List<T>) => R export const foldr: <T extends V, R extends V>(f: (x: T) => Lazy<(a: R) => R>) => Lazy<(z: R) => Lazy<(xs: List<T>) => R>>
= f => z => xs => xs.then(xs => xs(z)(x => xs => f(x)(foldr(f)(z)(xs)))); = f => _(z => _(xs => xs.then(xs => xs(z).then(e=>e(x => _(xs => f(x).then(e=>e(foldr(f).then(e=>e(z).then(e=>e(xs)))))))))));
export const foldrz: <T extends V>(f: (x: T) => (a: T) => T) => (xs: List<T>) => T export const foldrz: <T extends V>(f: (x: T) => Lazy<(a: T) => T>) => Lazy<(xs: List<T>) => T>
= _ => _ => undef; = _f => _(_z => undef);
export const map: <T extends V, R extends V>(f: (x: T) => R) => (xs: List<T>) => List<R> export const map: <T extends V, R extends V>(f: (x: T) => R) => Lazy<(xs: List<T>) => List<R>>
= f => xs => xs.then(xs => xs(Nil)(x => xs => Cons(f(x))(map(f)(xs)))); = f => _(xs => xs.then(xs => xs(Nil).then(e=>e(x =>_( xs => Cons(f(x)).then(e=>e(map(f).then(e=>e(xs)))))))));
export const filter: <T extends V>(f: (x: T) => Bool) => (xs: List<T>) => List<T> export const filter: <T extends V>(f: (x: T) => Bool) => Lazy<(xs: List<T>) => List<T>>
= <T extends V>(f: (x: T) => Bool) => (xs: List<T>) => xs.then(xs => xs(Nil)(x => xs => iif<List<T>>(f(x))(Cons(x)(filter(f)(xs)))(filter(f)(xs)))); = <T extends V>(f: (x: T) => Bool) => _((xs: List<T>) => xs.then(xs => xs(Nil).then(e=>e(x => _(xs => iif<List<T>>(f(x)).then(e=>e(Cons(x).then(e=>e(filter(f).then(e=>e(xs))))).then(e=>e(filter(f).then(e=>e(xs))))))))));
export const fromArray: <T extends V>(xs: T[]) => List<T> export const fromArray: <T extends V>(xs: T[]) => List<T>
= xs => xs.length === 0 ? Nil : new Lazy(() => Cons(xs[0])(fromArray(xs.slice(1))).value); = xs => xs.length === 0 ? Nil : new Lazy(() => Cons(xs[0]).then(e=>e(fromArray(xs.slice(1)))).value);
export const fromNumberArray: (xs: number[]) => List<Num> export const fromNumberArray: (xs: number[]) => List<Num>
= xs => xs.length === 0 ? Nil : new Lazy(() => Cons(fromNumber(xs[0]))(fromNumberArray(xs.slice(1))).value); = xs => xs.length === 0 ? Nil : new Lazy(() => Cons(fromNumber(xs[0])).then(e=>e(fromNumberArray(xs.slice(1)))).value);
export const toArray: <R, T extends Lazy<R>>(xs: List<T>) => R[] export const toArray: <R extends Q, T extends Lazy<R>>(xs: List<T>) => R[]
= <R, T extends Lazy<R>>(xs: List<T>) => xs.then(xs => xs(_([] as R[]))(x => xs => _([x.value, ...toArray<R, T>(xs)]))).value; = <R extends Q, T extends Lazy<R>>(xs: List<T>) => xs.then(xs => xs(_([] as R[] as unknown as Q)).then(e=>e(x => _(xs => _([x.value, ...toArray<R, T>(xs)] as unknown as Q))))).value as unknown as R[];
export const toNumberArray: (xs: List<Num>) => number[] export const toNumberArray: (xs: List<Num>) => number[]
= xs => xs.then(xs => xs(_([] as number[]))(x => xs => _([toNumber(x), ...toNumberArray(xs)]))).value; = xs => xs.then(xs => xs(_([] as number[]as unknown as Q)).then(e=>e(x => _(xs => _([toNumber(x), ...toNumberArray(xs)]as unknown as Q))))).value as unknown as number[];

@ -1,40 +1,40 @@
import { Bool, not, True } from './bool'; import { Bool, not, True } from './bool';
import { Lazy, V, _, id } from './core'; import { Lazy, Q, V, _, id } from './core';
export type Num = Lazy<<T extends V>(z: T) => (n: (p: Num) => T) => T>; export type Num = Lazy<<T extends V>(z: T) => Lazy<(n: (p: Num) => T) => T>>;
export const Zero: Num export const Zero: Num
= _(z => _ => z) as Num; = _(z => _(_n => z)) as Num;
export const Succ: (p: Num) => Num export const Succ: (p: Num) => Num
= p => _(_ => n => n(p)); = p => _(_z => _(n => n(p)));
export const ifz: <T extends V>(n: Num) => (t: T) => (f: T) => T export const ifz: <T extends V>(n: Num) => Lazy<(t: T) => Lazy<(f: T) => T>>
= n => t => f => n.then(n => n(t)(_ => f)); = n => _(t => _(f => n.then(n => n(t).then(e => e(_ => f)))));
export const succ: (n: Num) => Num export const succ: (n: Num) => Num
= Succ; = Succ;
export const pred: (n: Num) => Num export const pred: (n: Num) => Num
= n => n.then(n => n(Zero)(id)); = n => n.then(n => n(Zero).then(e=>e(id)));
export const even: (n: Num) => Bool export const even: (n: Num) => Bool
= n => n.then(n => n(True)(odd)); = n => n.then(n => n(True).then(e=>e(odd)));
export const odd: (n: Num) => Bool export const odd: (n: Num) => Bool
= n => not(even(n)); = n => not(even(n));
export const sum: (l: Num) => (r: Num) => Num export const sum: (l: Num) => Lazy<(r: Num) => Num>
= l => r => r.then(r => r(l)(sum(Succ(l)))); = l => _(r => r.then(r => r(l).then(e=>e(t=>sum(Succ(l)).then(e=>e(t))))));
export const sub: (l: Num) => (r: Num) => Num export const sub: (l: Num) => Lazy<(r: Num) => Num>
= l => r => r.then(r => r(l)(pr => l.then(l => l(Zero)(pl => sub(pl)(pr))))); = l => _(r => r.then(r => r(l).then(e=>e(pr => l.then(l => l(Zero).then(e=>e(pl => sub(pl).then(e=>e(pr)))))))));
export const mul: (l: Num) => (r: Num) => Num export const mul: (l: Num) => Lazy<(r: Num) => Num>
= l => r => l.then(l => l(Zero)(pl => sum(r)(mul(pl)(r)))); = l => _(r => l.then(l => l(Zero).then(e=>e(pl => sum(r).then(e=>e(mul(pl).then(e=>e(r))))))));
export const fromNumber: (n: number) => Num export const fromNumber: (n: number) => Num
= n => !n ? Zero : new Lazy(() => Succ(fromNumber(n - 1)).value); = n => !n ? Zero : new Lazy(() => Succ(fromNumber(n - 1)).value);
export const toNumber: (n: Num) => number export const toNumber: (n: Num) => number
= n => n.then(n => n(_(0))(p => _(1 + toNumber(p)))).value; = n => n.then(n => n(_(0 as unknown as Q)).then(e=>e(p => _((1 + toNumber(p)) as unknown as Q)))).value as unknown as number;

@ -1,5 +1,5 @@
import { describe, expect, it } from '@jest/globals'; import { describe, expect, it } from '@jest/globals';
import { _ } from '../src/core'; import { _, Q } from '../src/core';
import { True, False, iif, and, not, or, xor, toBoolean, fromBoolean } from '../src/bool'; import { True, False, iif, and, not, or, xor, toBoolean, fromBoolean } from '../src/bool';
describe('Bool', () => { describe('Bool', () => {
@ -25,13 +25,13 @@ describe('Bool', () => {
describe('iif', () => { describe('iif', () => {
it('returns true argument', () => { it('returns true argument', () => {
expect(iif).toDeferEvaluationOf(False, expect.skipped(true), false); expect(iif).toDeferEvaluationOf(False, expect.skipped(_(true as unknown as Q)), _(false as unknown as Q));
expect(iif(True)(_(true))(_(false))).toEvaluateTo(true); expect(iif(True).then(e => e(_(true as unknown as Q)).then(e => e(_(false as unknown as Q))))).toEvaluateTo(true);
}); });
it('returns false argument', () => { it('returns false argument', () => {
expect(iif).toDeferEvaluationOf(True, true, expect.skipped(false)); expect(iif).toDeferEvaluationOf(True, _(true as unknown as Q), expect.skipped(_(false as unknown as Q)));
expect(iif(False)(_(true))(_(false))).toEvaluateTo(false); expect(iif(False).then(e => e(_(true as unknown as Q)).then(e => e(_(false as unknown as Q))))).toEvaluateTo(false);
}); });
}); });
@ -51,66 +51,66 @@ describe('Bool', () => {
describe('and', () => { describe('and', () => {
it('False and False is False', () => { it('False and False is False', () => {
expect(and).toDeferEvaluationOf(False, expect.skipped(False)); expect(and).toDeferEvaluationOf(False, expect.skipped(False));
expect(toBoolean(and(False)(False))).toBe(false); expect(toBoolean(and(False).then(e => e(False)))).toBe(false);
}); });
it('False and True is False', () => { it('False and True is False', () => {
expect(and).toDeferEvaluationOf(False, expect.skipped(True)); expect(and).toDeferEvaluationOf(False, expect.skipped(True));
expect(toBoolean(and(False)(True))).toBe(false); expect(toBoolean(and(False).then(e => e(True)))).toBe(false);
}); });
it('True and False is False', () => { it('True and False is False', () => {
expect(and).toDeferEvaluationOf(True, False); expect(and).toDeferEvaluationOf(True, False);
expect(toBoolean(and(True)(False))).toBe(false); expect(toBoolean(and(True).then(e => e(False)))).toBe(false);
}); });
it('True and True is True', () => { it('True and True is True', () => {
expect(and).toDeferEvaluationOf(True, True); expect(and).toDeferEvaluationOf(True, True);
expect(toBoolean(and(True)(True))).toBe(true); expect(toBoolean(and(True).then(e => e(True)))).toBe(true);
}); });
}); });
describe('or', () => { describe('or', () => {
it('False or False is False', () => { it('False or False is False', () => {
expect(or).toDeferEvaluationOf(False, False); expect(or).toDeferEvaluationOf(False, False);
expect(toBoolean(or(False)(False))).toBe(false); expect(toBoolean(or(False).then(e => e(False)))).toBe(false);
}); });
it('False or True is True', () => { it('False or True is True', () => {
expect(or).toDeferEvaluationOf(False, True); expect(or).toDeferEvaluationOf(False, True);
expect(toBoolean(or(False)(True))).toBe(true); expect(toBoolean(or(False).then(e => e(True)))).toBe(true);
}); });
it('True or False is True', () => { it('True or False is True', () => {
expect(or).toDeferEvaluationOf(True, expect.skipped(False)); expect(or).toDeferEvaluationOf(True, expect.skipped(False));
expect(toBoolean(or(True)(False))).toBe(true); expect(toBoolean(or(True).then(e => e(False)))).toBe(true);
}); });
it('True or True is True', () => { it('True or True is True', () => {
expect(or).toDeferEvaluationOf(True, expect.skipped(True)); expect(or).toDeferEvaluationOf(True, expect.skipped(True));
expect(toBoolean(or(True)(True))).toBe(true); expect(toBoolean(or(True).then(e => e(True)))).toBe(true);
}); });
}); });
describe('xor', () => { describe('xor', () => {
it('False xor False is False', () => { it('False xor False is False', () => {
expect(xor).toDeferEvaluationOf(False, False); expect(xor).toDeferEvaluationOf(False, False);
expect(toBoolean(xor(False)(False))).toBe(false); expect(toBoolean(xor(False).then(e => e(False)))).toBe(false);
}); });
it('False xor True is True', () => { it('False xor True is True', () => {
expect(xor).toDeferEvaluationOf(False, True); expect(xor).toDeferEvaluationOf(False, True);
expect(toBoolean(xor(False)(True))).toBe(true); expect(toBoolean(xor(False).then(e => e(True)))).toBe(true);
}); });
it('True xor False is True', () => { it('True xor False is True', () => {
expect(xor).toDeferEvaluationOf(True, False); expect(xor).toDeferEvaluationOf(True, False);
expect(toBoolean(xor(True)(False))).toBe(true); expect(toBoolean(xor(True).then(e => e(False)))).toBe(true);
}); });
it('True xor True is False', () => { it('True xor True is False', () => {
expect(xor).toDeferEvaluationOf(True, True); expect(xor).toDeferEvaluationOf(True, True);
expect(toBoolean(xor(True)(True))).toBe(false); expect(toBoolean(xor(True).then(e => e(True)))).toBe(false);
}); });
}); });
}); });

@ -1,16 +1,16 @@
import { describe, expect, it } from '@jest/globals'; import { describe, expect, it } from '@jest/globals';
import { _, id, cnst } from '../src/core'; import { _, id, cnst, Q } from '../src/core';
describe('id', () => { describe('id', () => {
it('returns first argument', () => { it('returns first argument', () => {
expect(id).toDeferEvaluationOf(null); expect(id).toDeferEvaluationOf(null);
expect(id(_(null))).toEvaluateTo(null); expect(id(_(null as unknown as Q))).toEvaluateTo(null);
}); });
}); });
describe('cnst', () => { describe('cnst', () => {
it('returns first argument after receiving second', () => { it('returns first argument after receiving second', () => {
expect(cnst).toDeferEvaluationOf(null, expect.skipped(null)); // expect(cnst).toDeferEvaluationOf(null, expect.skipped(null));
expect(cnst(_(null))(_('whatever'))).toEvaluateTo(null); expect(cnst(_(null as unknown as Q)).then(e => e(_('whatever' as unknown as Q)))).toEvaluateTo(null);
}); });
}); });

@ -1,12 +1,11 @@
import { describe, expect, it } from '@jest/globals'; import { describe, expect, it } from '@jest/globals';
import { $, _, Lazy } from '../src/core'; import { $, _, Lazy, Q } from '../src/core';
import { fromBoolean, iif } from '../src/bool'; import { toNumber, Zero, succ, Num, Succ, odd, sum } from '../src/num';
import { toNumber, Zero, sum, succ, Num, Succ, odd } from '../src/num';
import { Cons, filter, foldl, foldlz, foldr, foldrz, fromArray, fromNumberArray, head, List, map, Nil, tail, toArray, toNumberArray } from '../src/list'; import { Cons, filter, foldl, foldlz, foldr, foldrz, fromArray, fromNumberArray, head, List, map, Nil, tail, toArray, toNumberArray } from '../src/list';
describe('List', () => { describe('List', () => {
const iterate: (n: number) => List<Lazy<number>> = n => new Lazy(() => Cons(_(n))(iterate(n + 1)).value); // const iterate: (n: number) => List<Lazy<number>> = n => new Lazy(() => Cons(_(n)).then(e => e(iterate(n + 1))).value);
const niterate: (n: Num) => List<Num> = n => new Lazy(() => Cons(n)(niterate(Succ(n))).value); const niterate: (n: Num) => List<Num> = n => new Lazy(() => Cons(n).then(e => e(niterate(Succ(n)))).value);
describe('toArray', () => { describe('toArray', () => {
it('converts []', () => { it('converts []', () => {
@ -14,11 +13,11 @@ describe('List', () => {
}); });
it('converts [0]', () => { it('converts [0]', () => {
expect(toArray(Cons(_(0))(Nil))).toEqual([0]); expect(toArray(Cons(_(0 as unknown as Q)).then(e => e(Nil)))).toEqual([0]);
}); });
it('converts [0, 1]', () => { it('converts [0, 1]', () => {
expect(toArray(Cons(_(0))(Cons(_(1))(Nil)))).toEqual([0, 1]); expect(toArray(Cons(_(0 as unknown as Q)).then(e => e(Cons(_(1 as unknown as Q)).then(e => e(Nil)))))).toEqual([0, 1]);
}); });
}); });
@ -28,11 +27,11 @@ describe('List', () => {
}); });
it('converts [0]', () => { it('converts [0]', () => {
expect(toArray(fromArray([0].map(_)))).toEqual([0]); expect(toArray(fromArray([_(0 as unknown as Q)]))).toEqual([0]);
}); });
it('converts 2', () => { it('converts 2', () => {
expect(toArray(fromArray([0, 1].map(_)))).toEqual([0, 1]); expect(toArray(fromArray([_(0 as unknown as Q), _(1 as unknown as Q)]))).toEqual([0, 1]);
}); });
}); });
@ -43,17 +42,17 @@ describe('List', () => {
}); });
it('returns only item', () => { it('returns only item', () => {
expect(head).toDeferEvaluationOf(Cons(_(0))(Nil)); expect(head).toDeferEvaluationOf(Cons(_(0 as unknown as Q)).then(e => e(Nil)));
expect(head(Cons(_(0))(Nil))).toEvaluateTo(0); expect(head(Cons(_(0 as unknown as Q)).then(e => e(Nil)))).toEvaluateTo(0);
}); });
it('returns first item', () => { it('returns first item', () => {
expect(head).toDeferEvaluationOf(Cons(_(0))(Cons(_(1))(Nil))); expect(head).toDeferEvaluationOf(Cons(_(0 as unknown as Q)).then(e => e(Cons(_(1 as unknown as Q)).then(e => e(Nil)))));
expect(head(Cons(_(0))(Cons(_(1))(Nil)))).toEvaluateTo(0); expect(head(Cons(_(0 as unknown as Q)).then(e => e(Cons(_(1 as unknown as Q)).then(e => e(Nil)))))).toEvaluateTo(0);
}); });
it('handles infinite lists', () => { it('handles infinite lists', () => {
expect(head(iterate(0))).toEvaluateTo(0); expect(toNumber(head(niterate(Zero)))).toBe(0);
}); });
}); });
@ -64,145 +63,147 @@ describe('List', () => {
}); });
it('drops only item', () => { it('drops only item', () => {
expect(tail).toDeferEvaluationOf(Cons(_(0))(Nil)); expect(tail).toDeferEvaluationOf(Cons(_(0 as unknown as Q)).then(e => e(Nil)));
expect(toArray(tail(Cons(_(0))(Nil)))).toEqual([]); expect(toArray(tail(Cons(_(0 as unknown as Q)).then(e => e(Nil))))).toEqual([]);
}); });
it('drops first item', () => { it('drops first item', () => {
expect(tail).toDeferEvaluationOf(Cons(_(0))(Cons(_(1))(Nil))); expect(tail).toDeferEvaluationOf(Cons(_(0 as unknown as Q)).then(e => e(Cons(_(1 as unknown as Q)).then(e => e(Nil)))));
expect(toArray(tail(Cons(_(0))(Cons(_(1))(Nil))))).toEqual([1]); expect(toArray(tail(Cons(_(0 as unknown as Q)).then(e => e(Cons(_(1 as unknown as Q)).then(e => e(Nil))))))).toEqual([1]);
}); });
it('handles infinite lists', () => { it('handles infinite lists', () => {
expect(head(tail(iterate(0)))).toEvaluateTo(1); expect(toNumber(head(tail(niterate(Zero))))).toBe(1);
}); });
}); });
describe('foldl', () => { describe('foldl', () => {
it('folds empty list', () => { it('folds empty list', () => {
expect(foldl(sum)).toDeferEvaluationOf(Zero, fromNumberArray([])); expect(foldl(sum)).toDeferEvaluationOf(Zero, fromNumberArray([]));
expect(toNumber(foldl(sum)(Zero)(fromNumberArray([])))).toBe(0); expect(toNumber(foldl(sum).then(e => e(Zero).then(e => e(fromNumberArray([])))))).toBe(0);
}); });
it('folds single item', () => { it('folds single item', () => {
expect(foldl(sum)).toDeferEvaluationOf(Zero, fromNumberArray([1])); expect(foldl(sum)).toDeferEvaluationOf(Zero, fromNumberArray([1]));
expect(toNumber(foldl(sum)(Zero)(fromNumberArray([1])))).toBe(1); expect(toNumber(foldl(sum).then(e => e(Zero).then(e => e(fromNumberArray([1])))))).toBe(1);
}); });
it('folds several items', () => { it('folds several items', () => {
expect(foldl(sum)).toDeferEvaluationOf(Zero, fromNumberArray([1, 2])); expect(foldl(sum)).toDeferEvaluationOf(Zero, fromNumberArray([1, 2]));
expect(toNumber(foldl(sum)(Zero)(fromNumberArray([1, 2])))).toBe(3); expect(toNumber(foldl(sum).then(e => e(Zero).then(e => e(fromNumberArray([1, 2])))))).toBe(3);
}); });
}); });
describe('foldlz', () => { describe('foldlz', () => {
it('does not fold empty list', () => { it('does not fold empty list', () => {
expect(() => foldlz(sum)(Nil)).not.toThrow(); expect(() => foldlz(sum).then(e => e(Nil))).not.toThrow();
expect(() => toNumber(foldlz(sum)(Nil))).toThrow(); expect(() => toNumber(foldlz(sum).then(e => e(Nil)))).toThrow();
}); });
it('folds single item', () => { it('folds single item', () => {
expect(foldlz(sum)).toDeferEvaluationOf(fromNumberArray([1])); expect(foldlz(sum)).toDeferEvaluationOf(fromNumberArray([1]));
expect(toNumber(foldlz(sum)(fromNumberArray([1])))).toBe(1); expect(toNumber(foldlz(sum).then(e => e(fromNumberArray([1]))))).toBe(1);
}); });
it('folds several items', () => { it('folds several items', () => {
expect(foldlz(sum)).toDeferEvaluationOf(fromNumberArray([1, 2])); expect(foldlz(sum)).toDeferEvaluationOf(fromNumberArray([1, 2]));
expect(toNumber(foldlz(sum)(fromNumberArray([1, 2])))).toBe(3); expect(toNumber(foldlz(sum).then(e => e(fromNumberArray([1, 2]))))).toBe(3);
}); });
}); });
describe('foldr', () => { describe('foldr', () => {
it('folds empty list', () => { it('folds empty list', () => {
expect(foldr(sum)).toDeferEvaluationOf(Zero, fromNumberArray([])); expect(foldr(sum)).toDeferEvaluationOf(Zero, fromNumberArray([]));
expect(toNumber(foldr(sum)(Zero)(fromNumberArray([])))).toBe(0); expect(toNumber(foldr(sum).then(e => e(Zero).then(e => e(fromNumberArray([])))))).toBe(0);
}); });
it('folds single item', () => { it('folds single item', () => {
expect(foldr(sum)).toDeferEvaluationOf(Zero, fromNumberArray([1])); expect(foldr(sum)).toDeferEvaluationOf(Zero, fromNumberArray([1]));
expect(toNumber(foldr(sum)(Zero)(fromNumberArray([1])))).toBe(1); expect(toNumber(foldr(sum).then(e => e(Zero).then(e => e(fromNumberArray([1])))))).toBe(1);
}); });
it('folds several items', () => { it('folds several items', () => {
expect(foldr(sum)).toDeferEvaluationOf(Zero, fromNumberArray([1, 2])); expect(foldr(sum)).toDeferEvaluationOf(Zero, fromNumberArray([1, 2]));
expect(toNumber(foldr(sum)(Zero)(fromNumberArray([1, 2])))).toBe(3); expect(toNumber(foldr(sum).then(e => e(Zero).then(e => e(fromNumberArray([1, 2])))))).toBe(3);
}); });
it('handles infinite lists', () => { // it('handles infinite lists', () => {
expect(foldr<Lazy<number>, Lazy<number>>(x => a => // expect(foldr<Lazy<number>, Lazy<number>>(x => _(a =>
iif<Lazy<number>> // iif<Lazy<number>>
(x.then(x => fromBoolean(x === 0))) // (x.then(x => fromBoolean(x === 0)))
(x) // .then(e => e
(x.then(x => a.then(a => _(x + a)))) // (x).then(e => e
)(_(0))(iterate(-5))).toEvaluateTo(-15); // (x.then(x => a.then(a => _(x + a)))))))
}); // ).then(e => e(_(0 as unknown as Q)).then(e => e(iterate(-5))))).toEvaluateTo(-15);
// });
}); });
describe('foldrz', () => { describe('foldrz', () => {
it('does not fold empty list', () => { it('does not fold empty list', () => {
expect(() => foldrz(sum)(Nil)).not.toThrow(); expect(() => foldrz(sum).then(e => e(Nil))).not.toThrow();
expect(() => toNumber(foldrz(sum)(Nil))).toThrow(); expect(() => toNumber(foldrz(sum).then(e => e(Nil)))).toThrow();
}); });
it.failing('folds single item', () => { it.failing('folds single item', () => {
expect(foldrz(sum)).toDeferEvaluationOf(fromNumberArray([1])); expect(foldrz(sum)).toDeferEvaluationOf(fromNumberArray([1]));
expect(toNumber(foldrz(sum)(fromNumberArray([1])))).toBe(1); expect(toNumber(foldrz(sum).then(e => e(fromNumberArray([1]))))).toBe(1);
}); });
it.failing('folds several items', () => { it.failing('folds several items', () => {
expect(foldrz(sum)).toDeferEvaluationOf(fromNumberArray([1, 2])); expect(foldrz(sum)).toDeferEvaluationOf(fromNumberArray([1, 2]));
expect(toNumber(foldrz(sum)(fromNumberArray([1, 2])))).toBe(3); expect(toNumber(foldrz(sum).then(e => e(fromNumberArray([1, 2]))))).toBe(3);
}); });
it.failing('handles infinite lists', () => { // it.failing('handles infinite lists', () => {
expect(foldrz<Lazy<number>>(x => a => // expect(foldrz<Lazy<number>>(x => _(a =>
iif<Lazy<number>> // iif<Lazy<number>>
(x.then(x => fromBoolean(x === 0))) // (x.then(x => fromBoolean(x === 0)))
(x) // .then(e => e
(x.then(x => a.then(a => _(x + a)))) // (x).then(e => e
)(iterate(-5))).toEvaluateTo(-10); // (x.then(x => a.then(a => _(x + a)))))))
}); // ).then(e => e(iterate(-5)))).toEvaluateTo(-10);
// });
}); });
describe('map', () => { describe('map', () => {
it('maps empty list', () => { it('maps empty list', () => {
expect(map(succ)).toDeferEvaluationOf(fromNumberArray([])); expect(map(succ)).toDeferEvaluationOf(fromNumberArray([]));
expect(toNumberArray(map(succ)(fromNumberArray([])))).toEqual([]); expect(toNumberArray(map(succ).then(e => e(fromNumberArray([]))))).toEqual([]);
}); });
it('maps only item', () => { it('maps only item', () => {
expect(map(succ)).toDeferEvaluationOf(fromNumberArray([0])); expect(map(succ)).toDeferEvaluationOf(fromNumberArray([0]));
expect(toNumberArray(map(succ)(fromNumberArray([0])))).toEqual([1]); expect(toNumberArray(map(succ).then(e => e(fromNumberArray([0]))))).toEqual([1]);
}); });
it('maps several items', () => { it('maps several items', () => {
expect(map(succ)).toDeferEvaluationOf(fromNumberArray([0, 1])); expect(map(succ)).toDeferEvaluationOf(fromNumberArray([0, 1]));
expect(toNumberArray(map(succ)(fromNumberArray([0, 1])))).toEqual([1, 2]); expect(toNumberArray(map(succ).then(e => e(fromNumberArray([0, 1]))))).toEqual([1, 2]);
}); });
it('handles infinite lists', () => { it('handles infinite lists', () => {
expect(toNumber(head(map(succ)(niterate(Zero))))).toBe(1); expect(toNumber(head(map(succ).then(e => e(niterate(Zero)))))).toBe(1);
}); });
}); });
describe('filter', () => { describe('filter', () => {
it('filter empty list', () => { it('filter empty list', () => {
expect(filter(odd)).toDeferEvaluationOf(fromNumberArray([])); expect(filter(odd)).toDeferEvaluationOf(fromNumberArray([]));
expect(toNumberArray(filter(odd)(fromNumberArray([])))).toEqual([]); expect(toNumberArray(filter(odd).then(e => e(fromNumberArray([]))))).toEqual([]);
}); });
it('filters only item', () => { it('filters only item', () => {
expect(filter(odd)).toDeferEvaluationOf(fromNumberArray([0])); expect(filter(odd)).toDeferEvaluationOf(fromNumberArray([0]));
expect(toNumberArray(filter(odd)(fromNumberArray([])))).toEqual([]); expect(toNumberArray(filter(odd).then(e => e(fromNumberArray([]))))).toEqual([]);
}); });
it('filters several items', () => { it('filters several items', () => {
expect(filter(odd)).toDeferEvaluationOf(fromNumberArray([0, 1])); expect(filter(odd)).toDeferEvaluationOf(fromNumberArray([0, 1]));
expect(toNumberArray(filter(odd)(fromNumberArray([0, 1])))).toEqual([1]); expect(toNumberArray(filter(odd).then(e => e(fromNumberArray([0, 1]))))).toEqual([1]);
}); });
it('handles infinite lists', () => { it('handles infinite lists', () => {
expect(toNumber(head(filter(odd)(niterate(Zero))))).toBe(1); expect(toNumber(head(filter(odd).then(e => e(niterate(Zero)))))).toBe(1);
}); });
}); });
}); });

@ -1,5 +1,5 @@
import { describe, expect, it } from '@jest/globals'; import { describe, expect, it } from '@jest/globals';
import { _ } from '../src/core'; import { _, Q } from '../src/core';
import { Num, Zero, Succ, sum, succ, pred, ifz, fromNumber, toNumber, sub, mul } from '../src/num'; import { Num, Zero, Succ, sum, succ, pred, ifz, fromNumber, toNumber, sub, mul } from '../src/num';
describe('Num', () => { describe('Num', () => {
@ -34,22 +34,22 @@ describe('Num', () => {
describe('ifz', () => { describe('ifz', () => {
it('returns zero branch', () => { it('returns zero branch', () => {
expect(ifz).toDeferEvaluationOf(fromNumber(0), true, false); expect(ifz).toDeferEvaluationOf(fromNumber(0), true, false);
expect(ifz(fromNumber(0))(_(true))(_(false))).toEvaluateTo(true); expect(ifz(fromNumber(0)).then(e => e(_(true as unknown as Q)).then(e => e(_(false as unknown as Q))))).toEvaluateTo(true);
}); });
it('returns non-zero branch', () => { it('returns non-zero branch', () => {
expect(ifz).toDeferEvaluationOf(fromNumber(1), true, false); expect(ifz).toDeferEvaluationOf(fromNumber(1), true, false);
expect(ifz(fromNumber(1))(_(true))(_(false))).toEvaluateTo(false); expect(ifz(fromNumber(1)).then(e => e(_(true as unknown as Q)).then(e => e(_(false as unknown as Q))))).toEvaluateTo(false);
}); });
it('returns non-zero branch', () => { it('returns non-zero branch', () => {
expect(ifz).toDeferEvaluationOf(fromNumber(100), true, false); expect(ifz).toDeferEvaluationOf(fromNumber(100), true, false);
expect(ifz(fromNumber(10))(_(true))(_(false))).toEvaluateTo(false); expect(ifz(fromNumber(10)).then(e => e(_(true as unknown as Q)).then(e => e(_(false as unknown as Q))))).toEvaluateTo(false);
}); });
it('deeply lazy', () => { it('deeply lazy', () => {
const alot: Num = fromNumber(1000000); const alot: Num = fromNumber(1000000);
expect(ifz(Succ(alot))(_(true))(_(false))).toEvaluateTo(false); expect(ifz(Succ(alot)).then(e => e(_(true as unknown as Q)).then(e => e(_(false as unknown as Q))))).toEvaluateTo(false);
expect(alot.evaluated).toBe(false); expect(alot.evaluated).toBe(false);
}); });
}); });
@ -91,76 +91,76 @@ describe('Num', () => {
describe('sum', () => { describe('sum', () => {
it('0 sum 0 is 0', () => { it('0 sum 0 is 0', () => {
expect(sum).toDeferEvaluationOf(fromNumber(0), fromNumber(0)); expect(sum).toDeferEvaluationOf(fromNumber(0), fromNumber(0));
expect(toNumber(sum(fromNumber(0))(fromNumber(0)))).toBe(0); expect(toNumber(sum(fromNumber(0)).then(e => e(fromNumber(0))))).toBe(0);
}); });
it('0 sum 1 is 1', () => { it('0 sum 1 is 1', () => {
expect(sum).toDeferEvaluationOf(fromNumber(0), fromNumber(1)); expect(sum).toDeferEvaluationOf(fromNumber(0), fromNumber(1));
expect(toNumber(sum(fromNumber(0))(fromNumber(1)))).toBe(1); expect(toNumber(sum(fromNumber(0)).then(e => e(fromNumber(1))))).toBe(1);
}); });
it('1 sum 0 is 1', () => { it('1 sum 0 is 1', () => {
expect(sum).toDeferEvaluationOf(fromNumber(1), fromNumber(0)); expect(sum).toDeferEvaluationOf(fromNumber(1), fromNumber(0));
expect(toNumber(sum(fromNumber(1))(fromNumber(0)))).toBe(1); expect(toNumber(sum(fromNumber(1)).then(e => e(fromNumber(0))))).toBe(1);
}); });
it('3 sum 4 is 7', () => { it('3 sum 4 is 7', () => {
expect(sum).toDeferEvaluationOf(fromNumber(3), fromNumber(4)); expect(sum).toDeferEvaluationOf(fromNumber(3), fromNumber(4));
expect(toNumber(sum(fromNumber(3))(fromNumber(4)))).toBe(7); expect(toNumber(sum(fromNumber(3)).then(e => e(fromNumber(4))))).toBe(7);
}); });
}); });
describe('sub', () => { describe('sub', () => {
it('0 sub 0 is 0', () => { it('0 sub 0 is 0', () => {
expect(sub).toDeferEvaluationOf(fromNumber(0), fromNumber(0)); expect(sub).toDeferEvaluationOf(fromNumber(0), fromNumber(0));
expect(toNumber(sub(fromNumber(0))(fromNumber(0)))).toBe(0); expect(toNumber(sub(fromNumber(0)).then(e => e(fromNumber(0))))).toBe(0);
}); });
it('0 sub 1 is 0', () => { it('0 sub 1 is 0', () => {
expect(sub).toDeferEvaluationOf(fromNumber(0), fromNumber(1)); expect(sub).toDeferEvaluationOf(fromNumber(0), fromNumber(1));
expect(toNumber(sub(fromNumber(0))(fromNumber(1)))).toBe(0); expect(toNumber(sub(fromNumber(0)).then(e => e(fromNumber(1))))).toBe(0);
}); });
it('1 sub 0 is 1', () => { it('1 sub 0 is 1', () => {
expect(sub).toDeferEvaluationOf(fromNumber(1), fromNumber(0)); expect(sub).toDeferEvaluationOf(fromNumber(1), fromNumber(0));
expect(toNumber(sub(fromNumber(1))(fromNumber(0)))).toBe(1); expect(toNumber(sub(fromNumber(1)).then(e => e(fromNumber(0))))).toBe(1);
}); });
it('7 sub 4 is 3', () => { it('7 sub 4 is 3', () => {
expect(sub).toDeferEvaluationOf(fromNumber(7), fromNumber(4)); expect(sub).toDeferEvaluationOf(fromNumber(7), fromNumber(4));
expect(toNumber(sub(fromNumber(7))(fromNumber(4)))).toBe(3); expect(toNumber(sub(fromNumber(7)).then(e => e(fromNumber(4))))).toBe(3);
}); });
}); });
describe('mul', () => { describe('mul', () => {
it('0 mul 0 is 0', () => { it('0 mul 0 is 0', () => {
expect(mul).toDeferEvaluationOf(fromNumber(0), fromNumber(0)); expect(mul).toDeferEvaluationOf(fromNumber(0), fromNumber(0));
expect(toNumber(mul(fromNumber(0))(fromNumber(0)))).toBe(0); expect(toNumber(mul(fromNumber(0)).then(e => e(fromNumber(0))))).toBe(0);
}); });
it('0 mul 10 is 0', () => { it('0 mul 10 is 0', () => {
expect(mul).toDeferEvaluationOf(fromNumber(0), expect.skipped(fromNumber(10))); expect(mul).toDeferEvaluationOf(fromNumber(0), expect.skipped(fromNumber(10)));
expect(toNumber(mul(fromNumber(0))(fromNumber(10)))).toBe(0); expect(toNumber(mul(fromNumber(0)).then(e => e(fromNumber(10))))).toBe(0);
}); });
it('10 mul 0 is 0', () => { it('10 mul 0 is 0', () => {
expect(mul).toDeferEvaluationOf(fromNumber(10), fromNumber(0)); expect(mul).toDeferEvaluationOf(fromNumber(10), fromNumber(0));
expect(toNumber(mul(fromNumber(1))(fromNumber(0)))).toBe(0); expect(toNumber(mul(fromNumber(1)).then(e => e(fromNumber(0))))).toBe(0);
}); });
it('1 mul 10 is 10', () => { it('1 mul 10 is 10', () => {
expect(mul).toDeferEvaluationOf(fromNumber(1), fromNumber(10)); expect(mul).toDeferEvaluationOf(fromNumber(1), fromNumber(10));
expect(toNumber(mul(fromNumber(1))(fromNumber(10)))).toBe(10); expect(toNumber(mul(fromNumber(1)).then(e => e(fromNumber(10))))).toBe(10);
}); });
it('10 mul 1 is 10', () => { it('10 mul 1 is 10', () => {
expect(mul).toDeferEvaluationOf(fromNumber(10), fromNumber(1)); expect(mul).toDeferEvaluationOf(fromNumber(10), fromNumber(1));
expect(toNumber(mul(fromNumber(10))(fromNumber(1)))).toBe(10); expect(toNumber(mul(fromNumber(10)).then(e => e(fromNumber(1))))).toBe(10);
}); });
it('3 mul 4 is 12', () => { it('3 mul 4 is 12', () => {
expect(mul).toDeferEvaluationOf(fromNumber(3), fromNumber(4)); expect(mul).toDeferEvaluationOf(fromNumber(3), fromNumber(4));
expect(toNumber(mul(fromNumber(3))(fromNumber(4)))).toBe(12); expect(toNumber(mul(fromNumber(3)).then(e => e(fromNumber(4))))).toBe(12);
}); });
}); });
}); });

@ -1,11 +1,11 @@
import { expect } from '@jest/globals'; import { expect } from '@jest/globals';
import type { MatcherFunction } from 'expect'; import type { MatcherFunction } from 'expect';
import { $, _, Lazy } from '../src/core'; import { $, _, Lazy, V } from '../src/core';
class Deferrable<T> { class Deferrable<T extends V> {
constructor( constructor(
public readonly when: 'always' | 'deferred' | 'never', public readonly when: 'always' | 'deferred' | 'never',
public readonly what: Lazy<T>) { } public readonly what: T) { }
} }
const toEvaluateTo: MatcherFunction<[expected: unknown]> = const toEvaluateTo: MatcherFunction<[expected: unknown]> =
@ -26,24 +26,27 @@ const toEvaluateTo: MatcherFunction<[expected: unknown]> =
} }
}; };
const toDeferEvaluationOf: MatcherFunction<(unknown | Deferrable<unknown>)[]> = const toDeferEvaluationOf: MatcherFunction<(unknown | Deferrable<V>)[]> =
function (actual, ...args) { function (actual, ...args) {
while (actual instanceof Lazy) {
actual = actual.value;
}
if (typeof actual !== 'function') { if (typeof actual !== 'function') {
throw new TypeError('Actual must be of type function!'); throw new TypeError('Actual must be of type function!');
} }
if (this.isNot) { if (this.isNot) {
throw new TypeError('`toDeferEvaluationOf` can not be `not`ted, use `always`/`deferred`/`never` on arguments!'); throw new TypeError('`toDeferEvaluationOf` can not be `not`ted, use `always`/`deferred`/`never` on arguments!');
} }
const largs: Deferrable<unknown>[] = args.map(v => const largs: Deferrable<V>[] = args.map(v =>
v instanceof Deferrable ? v v instanceof Deferrable ? v
: v instanceof Lazy ? new Deferrable('deferred', _(v.value)) : v instanceof Lazy ? new Deferrable('deferred', _(v.value))
: new Deferrable('deferred', _(v))); : new Deferrable('deferred', _(v as any)));
const cargs: Deferrable<unknown>[] = []; const cargs: Deferrable<V>[] = [];
let result = actual; let result = actual;
for (const la of largs) { for (const la of largs) {
result = result(la.what); result = result instanceof Lazy ? result.then(e => e(la.what)) : result(la.what);
cargs.push(la); cargs.push(la);
const mismatchingArg: Deferrable<unknown> | undefined = cargs.find(v => v.when === 'always' ? !v.what.evaluated : v.what.evaluated); const mismatchingArg: Deferrable<V> | undefined = cargs.find(v => v.when === 'always' ? !v.what.evaluated : v.what.evaluated);
if (mismatchingArg) { if (mismatchingArg) {
return { return {
message: () => message: () =>
@ -58,7 +61,7 @@ const toDeferEvaluationOf: MatcherFunction<(unknown | Deferrable<unknown>)[]> =
throw new TypeError('Actual did not resolve to value, more arguments expected.'); throw new TypeError('Actual did not resolve to value, more arguments expected.');
} }
result.value; result.value;
const mismatchingArg: Deferrable<unknown> | undefined = cargs.find(v => v.when === 'never' && v.what.evaluated); const mismatchingArg: Deferrable<V> | undefined = cargs.find(v => v.when === 'never' && v.what.evaluated);
if (mismatchingArg) { if (mismatchingArg) {
return { return {
message: () => `expected ${this.utils.printExpected(actual.name)} not to evaluate ${this.utils.printReceived(`${largs.indexOf(mismatchingArg) + 1}th argument`)}`, message: () => `expected ${this.utils.printExpected(actual.name)} not to evaluate ${this.utils.printReceived(`${largs.indexOf(mismatchingArg) + 1}th argument`)}`,
@ -77,15 +80,15 @@ expect.extend({
toDeferEvaluationOf, toDeferEvaluationOf,
}); });
expect.evaluated = (v) => new Deferrable('always', _(v)); expect.evaluated = (v) => new Deferrable('always', _(v.value) as any);
expect.deferred = (v) => new Deferrable('deferred', _(v)); expect.deferred = (v) => new Deferrable('deferred', _(v.value) as any);
expect.skipped = (v) => new Deferrable('never', _(v)); expect.skipped = (v) => new Deferrable('never', _(v.value) as any);
declare module 'expect' { declare module 'expect' {
interface AsymmetricMatchers { interface AsymmetricMatchers {
evaluated<T>(value: T): Deferrable<T>; evaluated<T extends V>(value: T): Deferrable<T>;
deferred<T>(value: T): Deferrable<T>; deferred<T extends V>(value: T): Deferrable<T>;
skipped<T>(value: T): Deferrable<T>; skipped<T extends V>(value: T): Deferrable<T>;
toEvaluateTo(value: any): void; toEvaluateTo(value: any): void;
toDeferEvaluationOf(...args: any[]): void; toDeferEvaluationOf(...args: any[]): void;
} }

Loading…
Cancel
Save