From b3851fe11a6f345eb92af08f004d3b4d5cf36fe3 Mon Sep 17 00:00:00 2001 From: Aldwin Vlasblom Date: Mon, 7 Aug 2017 15:16:52 +0200 Subject: [PATCH] Remove "chainRec" named export --- README.md | 5 ++--- index.es.js | 1 - src/index.js | 2 -- test/4.chain-rec.test.js | 30 +++++++++++++++--------------- 4 files changed, 17 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index ea658c26..3e09b231 100644 --- a/README.md +++ b/README.md @@ -679,11 +679,10 @@ of `encaseN`, applying two or three arguments to the given function respectively #### chainRec -
chainRec :: ((a -> c, b -> c, a) -> Future e c, a) -> Future e b +
Future.chainRec :: ((a -> Next a, b -> Done b, a) -> Future e (Next a | Done b), a) -> Future e b ```hs -chainRec :: ((a -> c, b -> c, a) -> Future e c, a) -> Future e b -Future.chainRec :: ((a -> c, b -> c, a) -> Future e c, a) -> Future e b +Future.chainRec :: ((a -> Next a, b -> Done b, a) -> Future e (Next a | Done b), a) -> Future e b ```
diff --git a/index.es.js b/index.es.js index 79f034e8..8c15ff64 100644 --- a/index.es.js +++ b/index.es.js @@ -6,7 +6,6 @@ export * from './src/dispatchers'; export {after, rejectAfter} from './src/after'; export {attempt, attempt as try} from './src/attempt'; export {cache} from './src/cache'; -export {chainRec} from './src/chain-rec'; export {encase} from './src/encase'; export {encase2} from './src/encase2'; export {encase3} from './src/encase3'; diff --git a/src/index.js b/src/index.js index d530ce1b..be7cac9f 100644 --- a/src/index.js +++ b/src/index.js @@ -6,7 +6,6 @@ import * as dispatchers from './dispatchers'; import {after, rejectAfter} from './after'; import {attempt} from './attempt'; import {cache} from './cache'; -import {chainRec} from './chain-rec'; import {encase} from './encase'; import {encase2} from './encase2'; import {encase3} from './encase3'; @@ -34,7 +33,6 @@ export default Object.assign(Future, dispatchers, { after, attempt, cache, - chainRec, do: go, encase, encase2, diff --git a/test/4.chain-rec.test.js b/test/4.chain-rec.test.js index cf43e6fb..40fd1783 100644 --- a/test/4.chain-rec.test.js +++ b/test/4.chain-rec.test.js @@ -1,5 +1,5 @@ import {expect} from 'chai'; -import {Future, chainRec, of, after, reject} from '../index.es.js'; +import {Future, of, after, reject} from '../index.es.js'; import {isIteration} from '../src/internal/iteration'; import * as U from './util'; import type from 'sanctuary-type-identifiers'; @@ -7,12 +7,12 @@ import type from 'sanctuary-type-identifiers'; describe('chainRec()', () => { it('is a binary function', () => { - expect(chainRec).to.be.a('function'); - expect(chainRec.length).to.equal(2); + expect(Future.chainRec).to.be.a('function'); + expect(Future.chainRec.length).to.equal(2); }); it('returns an instance of Future', () => { - expect(chainRec(U.noop, 1)).to.be.an.instanceof(Future); + expect(Future.chainRec(U.noop, 1)).to.be.an.instanceof(Future); }); }); @@ -20,22 +20,22 @@ describe('chainRec()', () => { describe('ChainRec', () => { it('extends Future', () => { - expect(chainRec(U.noop, 1)).to.be.an.instanceof(Future); + expect(Future.chainRec(U.noop, 1)).to.be.an.instanceof(Future); }); it('is considered a member of fluture/Fluture', () => { - expect(type(chainRec(U.noop, 1))).to.equal(Future['@@type']); + expect(type(Future.chainRec(U.noop, 1))).to.equal(Future['@@type']); }); describe('#fork()', () => { it('does not break if the iteration does not contain a value key', () => { - const actual = chainRec((f, g, x) => (x, of({done: true})), 0); + const actual = Future.chainRec((f, g, x) => (x, of({done: true})), 0); return U.assertResolved(actual, undefined); }); it('calls the function with Next, Done and the initial value', () => { - chainRec((next, done, x) => { + Future.chainRec((next, done, x) => { expect(next).to.be.a('function'); expect(next.length).to.equal(1); expect(next(x)).to.satisfy(isIteration); @@ -49,36 +49,36 @@ describe('ChainRec', () => { it('calls the function with the value from the current iteration', () => { let i = 0; - chainRec((f, g, x) => { + Future.chainRec((f, g, x) => { expect(x).to.equal(i); return x < 5 ? of(f(++i)) : of(g(x)); }, i).fork(U.noop, U.noop); }); it('works asynchronously', () => { - const actual = chainRec((f, g, x) => after(10, x < 5 ? f(x + 1) : g(x)), 0); + const actual = Future.chainRec((f, g, x) => after(10, x < 5 ? f(x + 1) : g(x)), 0); return U.assertResolved(actual, 5); }); it('responds to failure', () => { - const m = chainRec((f, g, x) => reject(x), 1); + const m = Future.chainRec((f, g, x) => reject(x), 1); return U.assertRejected(m, 1); }); it('responds to failure after chaining async', () => { - const m = chainRec( + const m = Future.chainRec( (f, g, x) => x < 2 ? after(10, f(x + 1)) : reject(x), 0 ); return U.assertRejected(m, 2); }); it('can be cancelled straight away', done => { - chainRec((f, g, x) => after(10, g(x)), 1).fork(U.failRej, U.failRes)(); + Future.chainRec((f, g, x) => after(10, g(x)), 1).fork(U.failRej, U.failRes)(); setTimeout(done, 20); }); it('can be cancelled after some iterations', done => { - const m = chainRec((f, g, x) => after(10, x < 5 ? f(x + 1) : g(x)), 0); + const m = Future.chainRec((f, g, x) => after(10, x < 5 ? f(x + 1) : g(x)), 0); const cancel = m.fork(U.failRej, U.failRes); setTimeout(cancel, 25); setTimeout(done, 70); @@ -90,7 +90,7 @@ describe('ChainRec', () => { it('returns the code to create the ChainRec', () => { const f = (next, done, x) => next(x); - const m = chainRec(f, 1); + const m = Future.chainRec(f, 1); const s = `Future.chainRec(${f.toString()}, 1)`; expect(m.toString()).to.equal(s); });