Skip to content

Commit

Permalink
Integrate sanctuary-type-identifiers
Browse files Browse the repository at this point in the history
Closes #52
  • Loading branch information
Avaq committed Jan 4, 2017
1 parent 93fd5ab commit 89c6121
Show file tree
Hide file tree
Showing 31 changed files with 158 additions and 11 deletions.
18 changes: 13 additions & 5 deletions fluture.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,20 @@

/*istanbul ignore next*/
if(module && typeof module.exports !== 'undefined'){
module.exports = f(require('inspect-f'), require('sanctuary-type-classes'));
module.exports = f(
require('inspect-f'),
require('sanctuary-type-classes'),
require('sanctuary-type-identifiers')
);
}else{
global.Fluture = f(global.inspectf, global.sanctuaryTypeClasses);
global.Fluture = f(
global.inspectf,
global.sanctuaryTypeClasses,
global.sanctuaryTypeIdentifiers
);
}

}(/*istanbul ignore next*/(global || window || this), function(inspectf, Z){
}(/*istanbul ignore next*/(global || window || this), function(inspectf, Z, type){

'use strict';

Expand Down Expand Up @@ -44,7 +52,7 @@
}

function isFuture(m){
return m instanceof Future || Boolean(m) && m['@@type'] === TYPEOF_FUTURE;
return m instanceof Future || type(m) === TYPEOF_FUTURE;
}

function isThenable(m){
Expand Down Expand Up @@ -184,7 +192,7 @@
return new ChainRec(f, init);
}

Future.prototype['@@type'] = TYPEOF_FUTURE;
Future['@@type'] = TYPEOF_FUTURE;
Future.prototype._f = null;
Future.prototype.extractLeft = function Future$extractLeft(){ return [] };
Future.prototype.extractRight = function Future$extractRight(){ return [] };
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@
],
"dependencies": {
"inspect-f": "^1.2.0",
"sanctuary-type-classes": "^2.0.1"
"sanctuary-type-classes": "^2.0.1",
"sanctuary-type-identifiers": "^1.0.0"
},
"devDependencies": {
"babel-cli": "^6.18.0",
Expand All @@ -80,7 +81,6 @@
"remark-cli": "^2.1.0",
"remark-validate-links": "^5.0.0",
"rimraf": "^2.4.3",
"sanctuary": "^0.11.1",
"xyz": "^2.0.1"
}
}
7 changes: 3 additions & 4 deletions test/1.future.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ const expect = require('chai').expect;
const Future = require('../fluture.js');
const U = require('./util');
const F = require('./futures');
const S = require('sanctuary');
const type = require('sanctuary-type-identifiers');

describe('Future', () => {

it('instances are considered members of Future through @@type', () => {
expect(S.type(F.mock)).to.equal('fluture/Future');
expect(S.is(Future, F.mock)).to.equal(true);
it('instances are considered members of fluture/Future by sanctuary-type-identifiers', () => {
expect(type(F.mock)).to.equal('fluture/Future');
});

describe('.util', () => {
Expand Down
5 changes: 5 additions & 0 deletions test/2.safe-future.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const expect = require('chai').expect;
const Future = require('../fluture.js');
const SafeFuture = Future.classes.SafeFuture;
const U = require('./util');
const type = require('sanctuary-type-identifiers');

describe('Future()', () => {

Expand Down Expand Up @@ -36,6 +37,10 @@ describe('SafeFuture', () => {
expect(new SafeFuture).to.be.an.instanceof(Future);
});

it('is considered a member of fluture/Fluture', () => {
expect(type(new SafeFuture)).to.equal('fluture/Future');
});

describe('#fork()', () => {

it('throws TypeError when the computation returns nonsense', () => {
Expand Down
5 changes: 5 additions & 0 deletions test/3.future-after.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const expect = require('chai').expect;
const Future = require('../fluture.js');
const FutureAfter = Future.classes.FutureAfter;
const U = require('./util');
const type = require('sanctuary-type-identifiers');

describe('Future.after()', () => {

Expand Down Expand Up @@ -33,6 +34,10 @@ describe('FutureAfter', () => {
expect(m).to.be.an.instanceof(Future);
});

it('is considered a member of fluture/Fluture', () => {
expect(type(m)).to.equal('fluture/Future');
});

describe('#fork()', () => {

it('calls success callback with the value', () => {
Expand Down
5 changes: 5 additions & 0 deletions test/3.future-of.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const FL = require('fantasy-land');
const Future = require('../fluture.js');
const FutureOf = Future.classes.FutureOf;
const U = require('./util');
const type = require('sanctuary-type-identifiers');

describe('Future.of()', () => {

Expand All @@ -26,6 +27,10 @@ describe('FutureOf', () => {
expect(m).to.be.an.instanceof(Future);
});

it('is considered a member of fluture/Fluture', () => {
expect(type(m)).to.equal('fluture/Future');
});

describe('#fork()', () => {

it('calls success callback with the value', () => {
Expand Down
5 changes: 5 additions & 0 deletions test/3.future-reject-after.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const expect = require('chai').expect;
const Future = require('../fluture.js');
const FutureRejectAfter = Future.classes.FutureRejectAfter;
const U = require('./util');
const type = require('sanctuary-type-identifiers');

describe('Future.rejectAfter()', () => {

Expand Down Expand Up @@ -33,6 +34,10 @@ describe('FutureRejectAfter', () => {
expect(m).to.be.an.instanceof(Future);
});

it('is considered a member of fluture/Fluture', () => {
expect(type(m)).to.equal('fluture/Future');
});

describe('#fork()', () => {

it('calls failure callback with the reason', () => {
Expand Down
5 changes: 5 additions & 0 deletions test/3.future-reject.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const expect = require('chai').expect;
const Future = require('../fluture.js');
const FutureReject = Future.classes.FutureReject;
const U = require('./util');
const type = require('sanctuary-type-identifiers');

describe('Future.reject()', () => {

Expand All @@ -21,6 +22,10 @@ describe('FutureReject', () => {
expect(m).to.be.an.instanceof(Future);
});

it('is considered a member of fluture/Fluture', () => {
expect(type(m)).to.equal('fluture/Future');
});

describe('#fork()', () => {

it('calls failure callback with the reason', () => {
Expand Down
5 changes: 5 additions & 0 deletions test/4.chain-rec.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const expect = require('chai').expect;
const Future = require('../fluture.js');
const ChainRec = Future.classes.ChainRec;
const U = require('./util');
const type = require('sanctuary-type-identifiers');

describe('Future.class()', () => {

Expand Down Expand Up @@ -31,6 +32,10 @@ describe('ChainRec', () => {
expect(new ChainRec).to.be.an.instanceof(Future);
});

it('is considered a member of fluture/Fluture', () => {
expect(type(new ChainRec)).to.equal('fluture/Future');
});

describe('#fork()', () => {

it('throws TypeError when the given function does not return a Future', () => {
Expand Down
5 changes: 5 additions & 0 deletions test/5.cached-future.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const Future = require('../fluture.js');
const CachedFuture = Future.classes.CachedFuture;
const U = require('./util');
const F = require('./futures');
const type = require('sanctuary-type-identifiers');

describe('Future.cache()', () => {

Expand Down Expand Up @@ -38,6 +39,10 @@ describe('CachedFuture', () => {
expect(new CachedFuture).to.be.an.instanceof(Future);
});

it('is considered a member of fluture/Fluture', () => {
expect(type(new CachedFuture)).to.equal('fluture/Future');
});

describe('#fork()', () => {

it('resolves with the resolution value of the given Future', () => {
Expand Down
5 changes: 5 additions & 0 deletions test/5.future-and.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const Future = require('../fluture.js');
const FutureAnd = Future.classes.FutureAnd;
const U = require('./util');
const F = require('./futures');
const type = require('sanctuary-type-identifiers');

describe('Future.and()', () => {

Expand Down Expand Up @@ -55,6 +56,10 @@ describe('FutureAnd', () => {
expect(new FutureAnd).to.be.an.instanceof(Future);
});

it('is considered a member of fluture/Fluture', () => {
expect(type(new FutureAnd)).to.equal('fluture/Future');
});

describe('#fork()', () => {

describe('(res, res)', () => {
Expand Down
5 changes: 5 additions & 0 deletions test/5.future-ap.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const Future = require('../fluture.js');
const FutureAp = Future.classes.FutureAp;
const U = require('./util');
const F = require('./futures');
const type = require('sanctuary-type-identifiers');

describe('Future.ap()', () => {

Expand Down Expand Up @@ -62,6 +63,10 @@ describe('FutureAp', () => {
expect(new FutureAp).to.be.an.instanceof(Future);
});

it('is considered a member of fluture/Fluture', () => {
expect(type(new FutureAp)).to.equal('fluture/Future');
});

describe('#fork()', () => {

it('calls the function contained in the given Future to its contained value', () => {
Expand Down
5 changes: 5 additions & 0 deletions test/5.future-bimap.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const Future = require('../fluture.js');
const FutureBimap = Future.classes.FutureBimap;
const U = require('./util');
const F = require('./futures');
const type = require('sanctuary-type-identifiers');

describe('Future.bimap()', () => {

Expand Down Expand Up @@ -68,6 +69,10 @@ describe('FutureBimap', () => {
expect(new FutureBimap).to.be.an.instanceof(Future);
});

it('is considered a member of fluture/Fluture', () => {
expect(type(new FutureBimap)).to.equal('fluture/Future');
});

describe('#fork()', () => {

it('applies the first function to the value in the rejection branch', () => {
Expand Down
5 changes: 5 additions & 0 deletions test/5.future-both.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const Future = require('../fluture.js');
const FutureBoth = Future.classes.FutureBoth;
const U = require('./util');
const F = require('./futures');
const type = require('sanctuary-type-identifiers');

describe('Future.both()', () => {

Expand Down Expand Up @@ -55,6 +56,10 @@ describe('FutureBoth', () => {
expect(new FutureBoth).to.be.an.instanceof(Future);
});

it('is considered a member of fluture/Fluture', () => {
expect(type(new FutureBoth)).to.equal('fluture/Future');
});

describe('#fork()', () => {

describe('(res, res)', () => {
Expand Down
5 changes: 5 additions & 0 deletions test/5.future-chain-rej.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const Future = require('../fluture.js');
const FutureChainRej = Future.classes.FutureChainRej;
const U = require('./util');
const F = require('./futures');
const type = require('sanctuary-type-identifiers');

describe('Future.chainRej()', () => {

Expand Down Expand Up @@ -56,6 +57,10 @@ describe('FutureChainRej', () => {
expect(new FutureChainRej).to.be.an.instanceof(Future);
});

it('is considered a member of fluture/Fluture', () => {
expect(type(new FutureChainRej)).to.equal('fluture/Future');
});

describe('#fork()', () => {

it('calls the given function with the inner of the Future', () => {
Expand Down
5 changes: 5 additions & 0 deletions test/5.future-chain.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const Future = require('../fluture.js');
const FutureChain = Future.classes.FutureChain;
const U = require('./util');
const F = require('./futures');
const type = require('sanctuary-type-identifiers');

describe('Future.chain()', () => {

Expand Down Expand Up @@ -62,6 +63,10 @@ describe('FutureChain', () => {
expect(new FutureChain).to.be.an.instanceof(Future);
});

it('is considered a member of fluture/Fluture', () => {
expect(type(new FutureChain)).to.equal('fluture/Future');
});

describe('#fork()', () => {

it('calls the given function with the inner of the Future', () => {
Expand Down
5 changes: 5 additions & 0 deletions test/5.future-encase.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const expect = require('chai').expect;
const Future = require('../fluture.js');
const FutureEncase = Future.classes.FutureEncase;
const U = require('./util');
const type = require('sanctuary-type-identifiers');

const unaryNoop = a => void a;
const binaryNoop = (a, b) => void b;
Expand Down Expand Up @@ -82,6 +83,10 @@ describe('FutureEncase', () => {
expect(new FutureEncase).to.be.an.instanceof(Future);
});

it('is considered a member of fluture/Fluture', () => {
expect(type(new FutureEncase)).to.equal('fluture/Future');
});

describe('#fork()', () => {

describe('(unary)', () => {
Expand Down
5 changes: 5 additions & 0 deletions test/5.future-finally.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const Future = require('../fluture.js');
const FutureFinally = Future.classes.FutureFinally;
const U = require('./util');
const F = require('./futures');
const type = require('sanctuary-type-identifiers');

describe('Future.finally()', () => {

Expand Down Expand Up @@ -50,6 +51,10 @@ describe('FutureFinally', () => {
expect(new FutureFinally).to.be.an.instanceof(Future);
});

it('is considered a member of fluture/Fluture', () => {
expect(type(new FutureFinally)).to.equal('fluture/Future');
});

describe('#fork()', () => {

it('runs the second Future when the first resolves', done => {
Expand Down
5 changes: 5 additions & 0 deletions test/5.future-fold.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const Future = require('../fluture.js');
const FutureFold = Future.classes.FutureFold;
const U = require('./util');
const F = require('./futures');
const type = require('sanctuary-type-identifiers');

describe('Future.fold()', () => {

Expand Down Expand Up @@ -59,6 +60,10 @@ describe('FutureFold', () => {
expect(new FutureFold).to.be.an.instanceof(Future);
});

it('is considered a member of fluture/Fluture', () => {
expect(type(new FutureFold)).to.equal('fluture/Future');
});

describe('#fork()', () => {

it('resolves with the transformed rejection value', () => {
Expand Down
5 changes: 5 additions & 0 deletions test/5.future-from-forkable.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const U = require('./util');
const F = require('./futures');
const RamdaFuture = require('ramda-fantasy').Future;
const DataTask = require('data.task');
const type = require('sanctuary-type-identifiers');

describe('Future.fromForkable()', () => {

Expand All @@ -28,6 +29,10 @@ describe('FutureFromForkable', () => {
expect(new FutureFromForkable).to.be.an.instanceof(Future);
});

it('is considered a member of fluture/Fluture', () => {
expect(type(new FutureFromForkable)).to.equal('fluture/Future');
});

describe('#fork()', () => {

it('rejects if the Forkable calls the left', () => {
Expand Down
Loading

0 comments on commit 89c6121

Please sign in to comment.