Skip to content

Commit

Permalink
Remove "chainRec" named export
Browse files Browse the repository at this point in the history
  • Loading branch information
Avaq committed Aug 7, 2017
1 parent 721c036 commit b3851fe
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 21 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -679,11 +679,10 @@ of `encaseN`, applying two or three arguments to the given function respectively

#### chainRec

<details><summary><code>chainRec :: ((a -> c, b -> c, a) -> Future e c, a) -> Future e b</code></summary>
<details><summary><code>Future.chainRec :: ((a -> Next a, b -> Done b, a) -> Future e (Next a | Done b), a) -> Future e b</code></summary>

```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
```

</details>
Expand Down
1 change: 0 additions & 1 deletion index.es.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 0 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -34,7 +33,6 @@ export default Object.assign(Future, dispatchers, {
after,
attempt,
cache,
chainRec,
do: go,
encase,
encase2,
Expand Down
30 changes: 15 additions & 15 deletions test/4.chain-rec.test.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
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';

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);
});

});

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);
Expand All @@ -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);
Expand All @@ -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);
});
Expand Down

0 comments on commit b3851fe

Please sign in to comment.