Skip to content
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

test: use curried Z functions more broadly #326

Merged
merged 1 commit into from
Feb 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions test/A.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
'use strict';

var Z = require('sanctuary-type-classes');

var S = require('..');

var eq = require('./internal/eq');
var map = require('./internal/map');


test('A', function() {
Expand All @@ -14,6 +13,6 @@ test('A', function() {
eq(S.A.toString(), 'A :: (a -> b) -> a -> b');

eq(S.A(S.inc, 1), 2);
eq(Z.map(S.A(S.__, 100), [S.inc, Math.sqrt]), [101, 10]);
eq(map(S.A(S.__, 100))([S.inc, Math.sqrt]), [101, 10]);

});
5 changes: 2 additions & 3 deletions test/C.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
'use strict';

var Z = require('sanctuary-type-classes');

var S = require('..');

var eq = require('./internal/eq');
var map = require('./internal/map');


test('C', function() {
Expand All @@ -14,6 +13,6 @@ test('C', function() {
eq(S.C.toString(), 'C :: (a -> b -> c) -> b -> a -> c');

eq(S.C(S.concat, 'foo', 'bar'), 'barfoo');
eq(Z.map(S.C(S.concat, '!'), ['BAM', 'POW', 'KA-POW']), ['BAM!', 'POW!', 'KA-POW!']);
eq(map(S.C(S.concat, '!'))(['BAM', 'POW', 'KA-POW']), ['BAM!', 'POW!', 'KA-POW!']);

});
24 changes: 12 additions & 12 deletions test/Either/Either.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
'use strict';

var jsc = require('jsverify');
var Z = require('sanctuary-type-classes');

var S = require('../internal/sanctuary');

var EitherArb = require('../internal/EitherArb');
var Identity = require('../internal/Identity');
var IdentityArb = require('../internal/IdentityArb');
var equals = require('../internal/equals');
var laws = require('../internal/laws');
var squareRoot = require('../internal/squareRoot');

Expand Down Expand Up @@ -37,7 +37,7 @@ suite('Either', function() {

suite('Semigroup laws', function() {

var semigroupLaws = laws.Semigroup(Z.equals);
var semigroupLaws = laws.Semigroup(equals);

semigroupLaws.associativity(
EitherArb(jsc.string, jsc.string),
Expand All @@ -49,7 +49,7 @@ suite('Either', function() {

suite('Functor laws', function() {

var functorLaws = laws.Functor(Z.equals);
var functorLaws = laws.Functor(equals);

functorLaws.identity(
EitherArb(jsc.string, jsc.number)
Expand All @@ -65,7 +65,7 @@ suite('Either', function() {

suite('Bifunctor laws', function() {

var bifunctorLaws = laws.Bifunctor(Z.equals);
var bifunctorLaws = laws.Bifunctor(equals);

bifunctorLaws.identity(
EitherArb(jsc.string, jsc.number)
Expand All @@ -83,7 +83,7 @@ suite('Either', function() {

suite('Apply laws', function() {

var applyLaws = laws.Apply(Z.equals);
var applyLaws = laws.Apply(equals);

applyLaws.composition(
EitherArb(jsc.string, jsc.constant(Math.sqrt)),
Expand All @@ -95,7 +95,7 @@ suite('Either', function() {

suite('Applicative laws', function() {

var applicativeLaws = laws.Applicative(Z.equals, S.Either);
var applicativeLaws = laws.Applicative(equals, S.Either);

applicativeLaws.identity(
EitherArb(jsc.string, jsc.number)
Expand All @@ -115,7 +115,7 @@ suite('Either', function() {

suite('Chain laws', function() {

var chainLaws = laws.Chain(Z.equals);
var chainLaws = laws.Chain(equals);

chainLaws.associativity(
EitherArb(jsc.string, jsc.array(jsc.number)),
Expand All @@ -127,7 +127,7 @@ suite('Either', function() {

suite('Monad laws', function() {

var monadLaws = laws.Monad(Z.equals, S.Either);
var monadLaws = laws.Monad(equals, S.Either);

monadLaws.leftIdentity(
jsc.constant(squareRoot),
Expand All @@ -142,7 +142,7 @@ suite('Either', function() {

suite('Alt laws', function() {

var altLaws = laws.Alt(Z.equals);
var altLaws = laws.Alt(equals);

altLaws.associativity(
EitherArb(jsc.string, jsc.number),
Expand All @@ -160,7 +160,7 @@ suite('Either', function() {

suite('Foldable laws', function() {

var foldableLaws = laws.Foldable(Z.equals);
var foldableLaws = laws.Foldable(equals);

foldableLaws.associativity(
jsc.constant(function(x, y) { return x + y; }),
Expand All @@ -172,7 +172,7 @@ suite('Either', function() {

suite('Traversable laws', function() {

var traversableLaws = laws.Traversable(Z.equals);
var traversableLaws = laws.Traversable(equals);

traversableLaws.naturality(
jsc.constant(S.compose(S.Just, S.prop('value'))),
Expand All @@ -196,7 +196,7 @@ suite('Either', function() {

suite('Extend laws', function() {

var extendLaws = laws.Extend(Z.equals);
var extendLaws = laws.Extend(equals);

extendLaws.associativity(
EitherArb(jsc.string, jsc.integer),
Expand Down
28 changes: 14 additions & 14 deletions test/Maybe/Maybe.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
'use strict';

var jsc = require('jsverify');
var Z = require('sanctuary-type-classes');

var S = require('../internal/sanctuary');

var EitherArb = require('../internal/EitherArb');
var Identity = require('../internal/Identity');
var IdentityArb = require('../internal/IdentityArb');
var MaybeArb = require('../internal/MaybeArb');
var equals = require('../internal/equals');
var laws = require('../internal/laws');


Expand Down Expand Up @@ -37,7 +37,7 @@ suite('Maybe', function() {

suite('Semigroup laws', function() {

var semigroupLaws = laws.Semigroup(Z.equals);
var semigroupLaws = laws.Semigroup(equals);

semigroupLaws.associativity(
MaybeArb(jsc.string),
Expand All @@ -49,7 +49,7 @@ suite('Maybe', function() {

suite('Monoid laws', function() {

var monoidLaws = laws.Monoid(Z.equals, S.Maybe);
var monoidLaws = laws.Monoid(equals, S.Maybe);

monoidLaws.leftIdentity(
MaybeArb(jsc.string)
Expand All @@ -63,7 +63,7 @@ suite('Maybe', function() {

suite('Functor laws', function() {

var functorLaws = laws.Functor(Z.equals);
var functorLaws = laws.Functor(equals);

functorLaws.identity(
MaybeArb(jsc.number)
Expand All @@ -79,7 +79,7 @@ suite('Maybe', function() {

suite('Apply laws', function() {

var applyLaws = laws.Apply(Z.equals);
var applyLaws = laws.Apply(equals);

applyLaws.composition(
MaybeArb(jsc.constant(Math.sqrt)),
Expand All @@ -91,7 +91,7 @@ suite('Maybe', function() {

suite('Applicative laws', function() {

var applicativeLaws = laws.Applicative(Z.equals, S.Maybe);
var applicativeLaws = laws.Applicative(equals, S.Maybe);

applicativeLaws.identity(
MaybeArb(jsc.number)
Expand All @@ -111,7 +111,7 @@ suite('Maybe', function() {

suite('Chain laws', function() {

var chainLaws = laws.Chain(Z.equals);
var chainLaws = laws.Chain(equals);

chainLaws.associativity(
MaybeArb(jsc.array(jsc.asciistring)),
Expand All @@ -123,7 +123,7 @@ suite('Maybe', function() {

suite('Monad laws', function() {

var monadLaws = laws.Monad(Z.equals, S.Maybe);
var monadLaws = laws.Monad(equals, S.Maybe);

monadLaws.leftIdentity(
jsc.constant(S.head),
Expand All @@ -138,7 +138,7 @@ suite('Maybe', function() {

suite('Alt laws', function() {

var altLaws = laws.Alt(Z.equals);
var altLaws = laws.Alt(equals);

altLaws.associativity(
MaybeArb(jsc.number),
Expand All @@ -156,7 +156,7 @@ suite('Maybe', function() {

suite('Plus laws', function() {

var plusLaws = laws.Plus(Z.equals, S.Maybe);
var plusLaws = laws.Plus(equals, S.Maybe);

plusLaws.leftIdentity(
MaybeArb(jsc.number)
Expand All @@ -174,7 +174,7 @@ suite('Maybe', function() {

suite('Alternative laws', function() {

var alternativeLaws = laws.Alternative(Z.equals, S.Maybe);
var alternativeLaws = laws.Alternative(equals, S.Maybe);

alternativeLaws.distributivity(
MaybeArb(jsc.number),
Expand All @@ -190,7 +190,7 @@ suite('Maybe', function() {

suite('Foldable laws', function() {

var foldableLaws = laws.Foldable(Z.equals);
var foldableLaws = laws.Foldable(equals);

foldableLaws.associativity(
jsc.constant(function(x, y) { return x + y; }),
Expand All @@ -202,7 +202,7 @@ suite('Maybe', function() {

suite('Traversable laws', function() {

var traversableLaws = laws.Traversable(Z.equals);
var traversableLaws = laws.Traversable(equals);

traversableLaws.naturality(
jsc.constant(S.eitherToMaybe),
Expand All @@ -226,7 +226,7 @@ suite('Maybe', function() {

suite('Extend laws', function() {

var extendLaws = laws.Extend(Z.equals);
var extendLaws = laws.Extend(equals);

extendLaws.associativity(
MaybeArb(jsc.integer),
Expand Down
5 changes: 2 additions & 3 deletions test/T.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
'use strict';

var Z = require('sanctuary-type-classes');

var S = require('..');

var eq = require('./internal/eq');
var map = require('./internal/map');


test('T', function() {
Expand All @@ -14,6 +13,6 @@ test('T', function() {
eq(S.T.toString(), 'T :: a -> (a -> b) -> b');

eq(S.T(42, S.inc), 43);
eq(Z.map(S.T(100), [S.inc, Math.sqrt]), [101, 10]);
eq(map(S.T(100))([S.inc, Math.sqrt]), [101, 10]);

});
5 changes: 2 additions & 3 deletions test/flip.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
'use strict';

var Z = require('sanctuary-type-classes');

var S = require('..');

var eq = require('./internal/eq');
var map = require('./internal/map');


test('flip', function() {
Expand All @@ -13,7 +12,7 @@ test('flip', function() {
eq(S.flip.length, 3);
eq(S.flip.toString(), 'flip :: ((a, b) -> c) -> b -> a -> c');

eq(Z.map(S.flip(Math.pow, 2), [1, 2, 3, 4, 5]), [1, 4, 9, 16, 25]);
eq(map(S.flip(Math.pow, 2))([1, 2, 3, 4, 5]), [1, 4, 9, 16, 25]);
eq(S.flip(S.indexOf, ['a', 'b', 'c', 'd'], 'c'), S.Just(2));

});
File renamed without changes.
17 changes: 11 additions & 6 deletions test/internal/Compose.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
'use strict';

var FL = require('fantasy-land');
var Z = require('sanctuary-type-classes');

var ap = require('./ap');
var equals = require('./equals');
var map = require('./map');
var of = require('./of');
var toString = require('./toString');


// Compose :: (Apply f, Apply g) => { of :: b -> f b } -> { of :: c -> g c } -> f (g a) -> Compose f g a
Expand All @@ -15,19 +20,19 @@ module.exports = function Compose(F) {
ComposeFG['@@type'] = 'sanctuary/Compose';

ComposeFG[FL.of] = function(x) {
return ComposeFG(Z.of(F, Z.of(G, x)));
return ComposeFG(of(F)(of(G)(x)));
};

ComposeFG.prototype[FL.equals] = function(other) {
return Z.equals(this.value, other.value);
return equals(this.value)(other.value);
};

ComposeFG.prototype[FL.map] = function(f) {
return ComposeFG(Z.map(function(y) { return Z.map(f, y); }, this.value));
return ComposeFG(map(map(f))(this.value));
};

ComposeFG.prototype[FL.ap] = function(other) {
return ComposeFG(Z.ap(Z.map(function(u) { return function(y) { return Z.ap(u, y); }; }, other.value), this.value));
return ComposeFG(ap(map(ap)(other.value))(this.value));
};

// name :: TypeRep a -> String
Expand All @@ -41,7 +46,7 @@ module.exports = function Compose(F) {
ComposeFG.prototype.toString = function() {
return 'Compose(' + name(F) + ')' +
'(' + name(G) + ')' +
'(' + Z.toString(this.value) + ')';
'(' + toString(this.value) + ')';
};

return ComposeFG;
Expand Down
7 changes: 4 additions & 3 deletions test/internal/EitherArb.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
'use strict';

var jsc = require('jsverify');
var Z = require('sanctuary-type-classes');

var S = require('./sanctuary');

var toString = require('./toString');


// EitherArb :: Arbitrary a -> Arbitrary b -> Arbitrary (Either a b)
module.exports = function EitherArb(lArb, rArb) {
return jsc.oneof(lArb.smap(S.Left, S.prop('value'), Z.toString),
rArb.smap(S.Right, S.prop('value'), Z.toString));
return jsc.oneof(lArb.smap(S.Left, S.prop('value'), toString),
rArb.smap(S.Right, S.prop('value'), toString));
};
Loading