More library functions
This commit is contained in:
+11
-3
@@ -4,12 +4,11 @@ import { toNOrd as $o, NOrd } from '../src/ord';
|
||||
import { toBoolean as $b, iif } from '../src/bool';
|
||||
import { toNumber as $n, toNumber as $nn, Num, Succ, Zero, fromNumber as _n, fromNumber as _nn, cmp as cmpn, eq as eqn, even, gt as ngt, show as nshow, odd, succ, sum } from '../src/num';
|
||||
import { toChar as $c } from '../src/char';
|
||||
import { toArray as $a, Cons, List, Nil, fromArray as _a, all, any, append, cmp, concat, cons, eq, filter, foldl, foldlz, foldr, foldrz, ge, get, gt, head, intersperse, le, len, lt, map, nul, set, show, snoc, tail, update } from '../src/list';
|
||||
import { toArray as $a, Cons, List, Nil, fromArray as _a, all, any, append, cmp, concat, cons, eq, filter, foldl, foldlz, foldr, foldrz, ge, get, gt, head, intersperse, iterate, le, len, lt, map, nul, set, show, snoc, tail, update } from '../src/list';
|
||||
import { toString as $s } from '../src/string';
|
||||
|
||||
describe('List', () => {
|
||||
const iterate: (n: Num) => List<Num> = n => new L(() => Cons._(n)._(iterate(Succ._(n))).value);
|
||||
const infinite: List<Num> = iterate(Zero);
|
||||
const infinite: List<Num> = iterate._(Succ)._(Zero);
|
||||
|
||||
const _na: (xs: number[]) => List<Num>
|
||||
= xs => xs.length === 0 ? Nil : Cons._(_nn(xs[0]))._(new L(() => _na(xs.slice(1)).value));
|
||||
@@ -163,6 +162,15 @@ describe('List', () => {
|
||||
// });
|
||||
// });
|
||||
|
||||
// describe('iterate', () => {
|
||||
// it('iterate succ 0 is [0, 1, 2, ...]', () => {
|
||||
// expect($na(
|
||||
// iterate._(_n(0))._<List<Num>>(_((x0: Num) => _((x1s: List<Num>) =>
|
||||
// x1s._<List<Num>>(_((x1: Num) => _((x2s: List<Num>) =>
|
||||
// x2s._<List<Num>>(_((x2: Num) => _((_xrs: List<Num>): List<Num> => cons._(x0)._(cons._(x1)._(cons._(x2)._(Nil)))))))))))))).toEqual([0, 1, 2]);
|
||||
// });
|
||||
// });
|
||||
|
||||
describe('head', () => {
|
||||
it('returns nothing from Nil', () => {
|
||||
expect(() => $$(head._(Nil))).toThrow();
|
||||
|
||||
@@ -37,6 +37,25 @@ describe('String', () => {
|
||||
});
|
||||
});
|
||||
|
||||
// describe('repeat', () => {
|
||||
// it('repeat "a" is "aaa..."', () => {
|
||||
// expect($na(
|
||||
// repeat._(_s('a'))._<String>(_((x0: Char) => _((x1s: String) =>
|
||||
// x1s._<String>(_((x1: Char) => _((x2s: String) =>
|
||||
// x2s._<String>(_((x2: Char) => _((_xrs: String): String => cons._(x0)._(cons._(x1)._(cons._(x2)._(Nil)))))))))))))).toEqual('aaa');
|
||||
// });
|
||||
// });
|
||||
|
||||
// describe('iterate', () => {
|
||||
// it('iterate succ "a" is "abc..."', () => {
|
||||
// expect($na(
|
||||
// iterate._(_s('a'))._<String>(_((x0: Char) => _((x1s: String) =>
|
||||
// x1s._<String>(_((x1: Char) => _((x2s: String) =>
|
||||
// x2s._<String>(_((x2: Char) => _((_xrs: String): String => cons._(x0)._(cons._(x1)._(cons._(x2)._(Nil)))))))))))))).toEqual('abc');
|
||||
// });
|
||||
// });
|
||||
|
||||
|
||||
describe('empty', () => {
|
||||
it('empty "" is True', () => {
|
||||
expect($b(empty._(_s('')))).toEqual(true);
|
||||
|
||||
Reference in New Issue
Block a user