Skip to content

Commit 50c6b57

Browse files
authored
extract Just related duplicated code (ramda#3276)
* Use Maybe.Just and Maybe.Nothing instead * import Just, Nothing directly from Maybe.js
1 parent dec329d commit 50c6b57

21 files changed

Lines changed: 26 additions & 108 deletions

test/difference.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
var R = require('../source/index.js');
22
var eq = require('./shared/eq.js');
3+
var {Just} = require('./shared/Maybe.js');
34

45

56
describe('difference', function() {
@@ -18,11 +19,6 @@ describe('difference', function() {
1819
});
1920

2021
it('has R.equals semantics', function() {
21-
function Just(x) { this.value = x; }
22-
Just.prototype.equals = function(x) {
23-
return x instanceof Just && R.equals(x.value, this.value);
24-
};
25-
2622
eq(R.difference([0], [-0]).length, 1);
2723
eq(R.difference([-0], [0]).length, 1);
2824
eq(R.difference([NaN], [NaN]).length, 0);

test/dropRepeats.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
var R = require('../source/index.js');
22
var eq = require('./shared/eq.js');
3+
var {Just} = require('./shared/Maybe.js');
34

45

56
describe('dropRepeats', function() {
@@ -21,11 +22,6 @@ describe('dropRepeats', function() {
2122
});
2223

2324
it('has R.equals semantics', function() {
24-
function Just(x) { this.value = x; }
25-
Just.prototype.equals = function(x) {
26-
return x instanceof Just && R.equals(x.value, this.value);
27-
};
28-
2925
eq(R.dropRepeats([0, -0]).length, 2);
3026
eq(R.dropRepeats([-0, 0]).length, 2);
3127
eq(R.dropRepeats([NaN, NaN]).length, 1);

test/eqBy.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
var R = require('../source/index.js');
22
var eq = require('./shared/eq.js');
3+
var {Just} = require('./shared/Maybe.js');
34

45

56
describe('eqBy', function() {
@@ -13,11 +14,6 @@ describe('eqBy', function() {
1314
});
1415

1516
it('has R.equals semantics', function() {
16-
function Just(x) { this.value = x; }
17-
Just.prototype.equals = function(x) {
18-
return x instanceof Just && R.equals(x.value, this.value);
19-
};
20-
2117
eq(R.eqBy(R.identity, 0, -0), false);
2218
eq(R.eqBy(R.identity, -0, 0), false);
2319
eq(R.eqBy(R.identity, NaN, NaN), true);

test/eqProps.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
var R = require('../source/index.js');
22
var eq = require('./shared/eq.js');
3+
var {Just} = require('./shared/Maybe.js');
34

45

56
describe('eqProps', function() {
@@ -9,11 +10,6 @@ describe('eqProps', function() {
910
});
1011

1112
it('has R.equals semantics', function() {
12-
function Just(x) { this.value = x; }
13-
Just.prototype.equals = function(x) {
14-
return x instanceof Just && R.equals(x.value, this.value);
15-
};
16-
1713
eq(R.eqProps('value', {value: 0}, {value: -0}), false);
1814
eq(R.eqProps('value', {value: -0}, {value: 0}), false);
1915
eq(R.eqProps('value', {value: NaN}, {value: NaN}), true);

test/filter.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
var R = require('../source/index.js');
22
var eq = require('./shared/eq.js');
3-
var Maybe = require('./shared/Maybe.js');
3+
var {Just} = require('./shared/Maybe.js');
44

55

66
describe('filter', function() {
@@ -33,7 +33,7 @@ describe('filter', function() {
3333
});
3434

3535
it('correctly uses fantasy-land implementations', function() {
36-
var m1 = Maybe.Just(-1);
36+
var m1 = Just(-1);
3737
var m2 = R.filter(function(x) { return x > 0; } , m1);
3838

3939
eq(m2.isNothing, true);

test/includes.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
var R = require('../source/index.js');
22
var eq = require('./shared/eq.js');
3+
var {Just} = require('./shared/Maybe.js');
34

45

56
describe('includes', function() {
@@ -16,11 +17,6 @@ describe('includes', function() {
1617
});
1718

1819
it('has R.equals semantics', function() {
19-
function Just(x) { this.value = x; }
20-
Just.prototype.equals = function(x) {
21-
return x instanceof Just && R.equals(x.value, this.value);
22-
};
23-
2420
eq(R.includes(0, [-0]), false);
2521
eq(R.includes(-0, [0]), false);
2622
eq(R.includes(NaN, [NaN]), true);

test/indexOf.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
var R = require('../source/index.js');
22
var eq = require('./shared/eq.js');
3+
var {Just} = require('./shared/Maybe.js');
34

45

56
describe('indexOf', function() {
@@ -46,11 +47,6 @@ describe('indexOf', function() {
4647
});
4748

4849
it('has R.equals semantics', function() {
49-
function Just(x) { this.value = x; }
50-
Just.prototype.equals = function(x) {
51-
return x instanceof Just && R.equals(x.value, this.value);
52-
};
53-
5450
eq(R.indexOf(0, [-0]), -1);
5551
eq(R.indexOf(-0, [0]), -1);
5652
eq(R.indexOf(NaN, [NaN]), 0);

test/intersection.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
var R = require('../source/index.js');
22
var eq = require('./shared/eq.js');
3+
var {Just} = require('./shared/Maybe.js');
34

45

56
describe('intersection', function() {
@@ -24,11 +25,6 @@ describe('intersection', function() {
2425
});
2526

2627
it('has R.equals semantics', function() {
27-
function Just(x) { this.value = x; }
28-
Just.prototype.equals = function(x) {
29-
return x instanceof Just && R.equals(x.value, this.value);
30-
};
31-
3228
eq(R.intersection([0], [-0]).length, 0);
3329
eq(R.intersection([-0], [0]).length, 0);
3430
eq(R.intersection([NaN], [NaN]).length, 1);

test/lastIndexOf.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
var R = require('../source/index.js');
22
var eq = require('./shared/eq.js');
3+
var {Just} = require('./shared/Maybe.js');
34

45

56
describe('lastIndexOf', function() {
@@ -37,11 +38,6 @@ describe('lastIndexOf', function() {
3738
});
3839

3940
it('has R.equals semantics', function() {
40-
function Just(x) { this.value = x; }
41-
Just.prototype.equals = function(x) {
42-
return x instanceof Just && R.equals(x.value, this.value);
43-
};
44-
4541
eq(R.lastIndexOf(0, [-0]), -1);
4642
eq(R.lastIndexOf(-0, [0]), -1);
4743
eq(R.lastIndexOf(NaN, [NaN]), 0);

test/lift.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
var R = require('../source/index.js');
33
var eq = require('./shared/eq.js');
4-
var Maybe = require('./shared/Maybe.js');
4+
var {Just} = require('./shared/Maybe.js');
55

66
var not = function(x) { return !x; };
77
var add3 = R.curry(function add3(a, b, c) {
@@ -40,7 +40,7 @@ describe('lift', function() {
4040

4141
it('works with other functors such as "Maybe"', function() {
4242
var addM = R.lift(R.add);
43-
eq(addM(Maybe.Just(3), Maybe.Just(5)), Maybe.Just(8));
43+
eq(addM(Just(3), Just(5)), Just(8));
4444
});
4545

4646
});

0 commit comments

Comments
 (0)