-
-
Notifications
You must be signed in to change notification settings - Fork 84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support FantasyLand 1.x #26
Changes from 3 commits
7ca739c
29ee4a0
e0af4cd
ae74c64
8c7ab4f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,11 +6,11 @@ const Readable = require('stream').Readable; | |
const jsc = require('jsverify'); | ||
const S = require('sanctuary'); | ||
const FL = { | ||
map: 'map', | ||
bimap: 'bimap', | ||
chain: 'chain', | ||
ap: 'ap', | ||
of: 'of' | ||
map: 'fantasy-land/map', | ||
bimap: 'fantasy-land/bimap', | ||
chain: 'fantasy-land/chain', | ||
ap: 'fantasy-land/ap', | ||
of: 'fantasy-land/of' | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suggest adding fantasy-land as a dev dependency and requiring it here to catch typos. :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ahh, that's a great idea! That way we're ensuring compatibility with the naming conventions of a specific FL version, without having a hard dependency to it! :D There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just curious why not actually add a hard dependency? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I mean I can understand not wanting a peer dependency, but what bad about a normal dependency? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I don't see compelling reasons to do so: sanctuary-js/sanctuary-type-classes#2 (comment). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FantasyLand comes with its own dependency tree which seems to me like unnecessary overhead. It's not much of a big deal, but if there's no practical difference, or even much of a code-reuse advantage, I consider it cleaner not to depend on it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Didn't know that, created a PR that fixes it fantasyland/fantasy-land#168 Other points are valid as well though, I understand it better now, thanks! |
||
|
||
const noop = () => {}; | ||
|
@@ -726,14 +726,14 @@ describe('Future', () => { | |
fs.forEach(f => expect(f).to.throw(TypeError, /Future/)); | ||
}); | ||
|
||
it('throws TypeError when not not called on Future<Function>', () => { | ||
it('throws TypeError when not not called with Future<Function>', () => { | ||
const xs = [NaN, {}, [], 1, 'a', new Date, undefined, null]; | ||
const fs = xs.map(x => () => Future.of(x).ap(Future.of(1)).fork(noop, noop)); | ||
const fs = xs.map(x => () => Future.of(1).ap(Future.of(x)).fork(noop, noop)); | ||
fs.forEach(f => expect(f).to.throw(TypeError, /Future/)); | ||
}); | ||
|
||
it('applies its inner to the inner of the other', () => { | ||
const actual = Future.of(add(1)).ap(Future.of(1)); | ||
it('calls the function contained in the given Future to its contained value', () => { | ||
const actual = Future.of(1).ap(Future.of(add(1))); | ||
return assertResolved(actual, 2); | ||
}); | ||
|
||
|
@@ -747,19 +747,19 @@ describe('Future', () => { | |
}); | ||
|
||
it('does not matter if the left resolves late', () => { | ||
const actual = Future.after(20, add(1)).ap(Future.of(1)); | ||
const actual = Future.after(20, 1).ap(Future.of(add(1))); | ||
return assertResolved(actual, 2); | ||
}); | ||
|
||
it('does not matter if the right resolves late', () => { | ||
const actual = Future.of(add(1)).ap(Future.after(20, 1)); | ||
const actual = Future.of(1).ap(Future.after(20, add(1))); | ||
return assertResolved(actual, 2); | ||
}); | ||
|
||
it('forks in parallel', function(){ | ||
this.slow(80); | ||
this.timeout(50); | ||
const actual = Future.after(30, add(1)).ap(Future.after(30, 1)); | ||
const actual = Future.after(30, 1).ap(Future.after(30, add(1))); | ||
return assertResolved(actual, 2); | ||
}); | ||
|
||
|
@@ -1283,6 +1283,7 @@ describe('Fantasy-Land Compliance', function(){ | |
const of = Future[FL.of]; | ||
|
||
const I = x => x; | ||
const T = x => f => f(x); | ||
const B = f => g => x => f(g(x)); | ||
|
||
const sub3 = x => x - 3; | ||
|
@@ -1312,23 +1313,23 @@ describe('Fantasy-Land Compliance', function(){ | |
|
||
describe('Apply', () => { | ||
test('composition', x => eq( | ||
of(sub3)[FL.map](B)[FL.ap](of(mul3))[FL.ap](of(x)), | ||
of(sub3)[FL.ap](of(mul3)[FL.ap](of(x))) | ||
of(x)[FL.ap](of(sub3)[FL.ap](of(mul3)[FL.map](B))), | ||
of(x)[FL.ap](of(sub3))[FL.ap](of(mul3)) | ||
)); | ||
}); | ||
|
||
describe('Applicative', () => { | ||
test('identity', x => eq( | ||
of(x), | ||
of(I)[FL.ap](of(x)) | ||
of(x)[FL.ap](of(I)), | ||
of(x) | ||
)); | ||
test('homomorphism', x => eq( | ||
of(sub3(x)), | ||
of(sub3)[FL.ap](of(x)) | ||
of(x)[FL.ap](of(sub3)), | ||
of(sub3(x)) | ||
)); | ||
test('interchange', x => eq( | ||
of(sub3)[FL.ap](of(x)), | ||
of(f => f(x))[FL.ap](of(sub3)) | ||
of(x)[FL.ap](of(sub3)), | ||
of(sub3)[FL.ap](of(T(x))) | ||
)); | ||
}); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be
1.0.1
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wish it could be
^1.0.0
, maybe I should just usemaster
and pin it once a2.0
comes out.