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 Feb 13, 2017
1 parent fcc8386 commit 02415d9
Show file tree
Hide file tree
Showing 30 changed files with 156 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 @@ -45,7 +53,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 @@ -148,7 +156,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 @@ -53,7 +53,8 @@
],
"dependencies": {
"inspect-f": "^1.2.0",
"sanctuary-type-classes": "^3.0.0"
"sanctuary-type-classes": "^3.0.0",
"sanctuary-type-identifiers": "^1.0.0"
},
"devDependencies": {
"babel-cli": "^6.18.0",
Expand All @@ -76,7 +77,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.future-and.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@ const expect = require('chai').expect;
const Future = require('../fluture.js');
const U = require('./util');
const F = require('./futures');
const type = require('sanctuary-type-identifiers');

const testInstance = and => {

it('is considered a member of fluture/Fluture', () => {
expect(type(and(F.resolved, F.resolvedSlow))).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 @@ -4,9 +4,14 @@ const expect = require('chai').expect;
const Future = require('../fluture.js');
const U = require('./util');
const F = require('./futures');
const type = require('sanctuary-type-identifiers');

const testInstance = ap => {

it('is considered a member of fluture/Fluture', () => {
expect(type(ap(Future.of(1), Future.of(U.add(1))))).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 @@ -3,9 +3,14 @@
const expect = require('chai').expect;
const Future = require('../fluture.js');
const U = require('./util');
const type = require('sanctuary-type-identifiers');

const testInstance = bimap => {

it('is considered a member of fluture/Fluture', () => {
expect(type(bimap(Future.reject(1), U.add(1), U.failRes))).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 @@ -4,9 +4,14 @@ const expect = require('chai').expect;
const Future = require('../fluture.js');
const U = require('./util');
const F = require('./futures');
const type = require('sanctuary-type-identifiers');

const testInstance = both => {

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

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

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

const testInstance = cache => {

it('is considered a member of fluture/Fluture', () => {
expect(type(cache(Future.of(1)))).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-chain-rej.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@ const expect = require('chai').expect;
const Future = require('../fluture.js');
const U = require('./util');
const F = require('./futures');
const type = require('sanctuary-type-identifiers');

const testInstance = chainRej => {

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

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

it('calls the given function with the inner of the Future', done => {
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 @@ -4,9 +4,14 @@ const expect = require('chai').expect;
const Future = require('../fluture.js');
const U = require('./util');
const F = require('./futures');
const type = require('sanctuary-type-identifiers');

const testInstance = chain => {

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

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

it('calls the given function with the inner of the Future', done => {
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 @@ -83,6 +84,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 @@ -4,9 +4,14 @@ const expect = require('chai').expect;
const Future = require('../fluture.js');
const U = require('./util');
const F = require('./futures');
const type = require('sanctuary-type-identifiers');

const testInstance = fin => {

it('is considered a member of fluture/Fluture', () => {
expect(type(fin(Future.of(1), Future.of(2)))).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 @@ -3,9 +3,14 @@
const expect = require('chai').expect;
const Future = require('../fluture.js');
const U = require('./util');
const type = require('sanctuary-type-identifiers');

const testInstance = fold => {

it('is considered a member of fluture/Fluture', () => {
expect(type(fold(Future.reject(1), U.add(1), U.sub(1)))).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-promise.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 FutureFromPromise = Future.classes.FutureFromPromise;
const U = require('./util');
const type = require('sanctuary-type-identifiers');

const unaryNoop = a => Promise.resolve(a);
const binaryNoop = (a, b) => Promise.resolve(b);
Expand Down Expand Up @@ -84,6 +85,10 @@ describe('FutureFromPromise', () => {
expect(new FutureFromPromise).to.be.an.instanceof(Future);
});

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

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

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

const testInstance = hook => {

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

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

const m = F.resolved, xs = [NaN, {}, [], 1, 'a', new Date, undefined, null];
Expand Down
5 changes: 5 additions & 0 deletions test/5.future-map-rej.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@ const expect = require('chai').expect;
const Future = require('../fluture.js');
const U = require('./util');
const F = require('./futures');
const type = require('sanctuary-type-identifiers');

const testInstance = mapRej => {

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

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

it('applies the given function to its rejection reason', () => {
Expand Down
Loading

0 comments on commit 02415d9

Please sign in to comment.