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

use ES6 syntax #156

Merged
merged 1 commit into from
Apr 25, 2021
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
3 changes: 1 addition & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
{
"root": true,
"extends": ["./node_modules/sanctuary-style/eslint-es3.json"],
"extends": ["./node_modules/sanctuary-style/eslint-es6.json"],
"overrides": [
{
"files": ["*.md"],
"rules": {
"array-element-newline": ["off"],
"eqeqeq": ["off"],
"func-style": ["error", "declaration", {"allowArrowFunctions": true}],
"no-undef": ["off"],
"no-unused-vars": ["error", {"varsIgnorePattern": "^Bar$"}]
}
Expand Down
67 changes: 29 additions & 38 deletions bench/old-vs-new.js
Original file line number Diff line number Diff line change
@@ -1,54 +1,45 @@
'use strict';

var L = require ('list/fantasy-land');
var benchmark = require ('sanctuary-benchmark');
var Identity = require ('sanctuary-identity');
const L = require ('list/fantasy-land');
const benchmark = require ('sanctuary-benchmark');
const Identity = require ('sanctuary-identity');

var oldZ = require ('sanctuary-type-classes');
var newZ = require ('..');
const oldZ = require ('sanctuary-type-classes');
const newZ = require ('..');

var shuffle = require ('../test/shuffle');
const shuffle = require ('../test/shuffle');


// chainRecArrayNumber :: (Number -> c, Number -> c, Number) -> Array c
function chainRecArrayNumber(next, done, x) {
return [done (x), (x <= 1 ? done : next) (x - 1)];
}
const chainRecArrayNumber = (next, done, x) => (
[done (x), (x <= 1 ? done : next) (x - 1)]
);

// double :: a -> Array2 a a
function double(x) {
return [x, x];
}
const double = x => [x, x];

// inc :: Number -> Number
function inc(x) {
return x + 1;
}
const inc = x => x + 1;

// prep :: StrMap Function -> StrMap (Array2 (StrMap a) Function)
function prep(specs) {
return newZ.map (function(f) { return [{}, f]; }, specs);
}

var shuffledArray = (function() {
var xs = [];
for (var x = 0; x < 5000; x += 1) xs.push (x);
shuffle (xs);
return xs;
} ());
var shuffledList = L.fromArray (shuffledArray);
const prep = specs => newZ.map (f => [{}, f], specs);

const shuffledArray = [];
for (let x = 0; x < 5000; x += 1) shuffledArray.push (x);
shuffle (shuffledArray);
const shuffledList = L.fromArray (shuffledArray);

module.exports = benchmark (oldZ, newZ, {leftHeader: 'old', rightHeader: 'new'}, prep ({
'functions.chainRec.Array': function(Z) { Z.chainRec (Array, chainRecArrayNumber, 100); },
'functions.of.Array': function(Z) { Z.of (Array, 42); },
'functions.of.Identity': function(Z) { Z.of (Identity, 42); },
'methods.chain.Array': function(Z) { Z.chain (double, shuffledArray); },
'methods.equals.Identity': function(Z) { Z.equals (Identity (0), Identity (0)); },
'methods.equals.Object': function(Z) { Z.equals ({x: 0, y: 0}, {y: 0, x: 0}); },
'methods.map.Array': function(Z) { Z.map (inc, [1, 2, 3]); },
'methods.map.Identity': function(Z) { Z.map (inc, Identity (1)); },
'methods.sort.Array': function(Z) { Z.sort (shuffledArray); },
'methods.sort.List': function(Z) { Z.sort (shuffledList); },
'test.Comonad.Identity': function(Z) { Z.Comonad.test (Identity (0)); },
'test.Contravariant.Function': function(Z) { Z.Contravariant.test (Math.abs); }
'functions.chainRec.Array': Z => { Z.chainRec (Array, chainRecArrayNumber, 100); },
'functions.of.Array': Z => { Z.of (Array, 42); },
'functions.of.Identity': Z => { Z.of (Identity, 42); },
'methods.chain.Array': Z => { Z.chain (double, shuffledArray); },
'methods.equals.Identity': Z => { Z.equals (Identity (0), Identity (0)); },
'methods.equals.Object': Z => { Z.equals ({x: 0, y: 0}, {y: 0, x: 0}); },
'methods.map.Array': Z => { Z.map (inc, [1, 2, 3]); },
'methods.map.Identity': Z => { Z.map (inc, Identity (1)); },
'methods.sort.Array': Z => { Z.sort (shuffledArray); },
'methods.sort.List': Z => { Z.sort (shuffledList); },
'test.Comonad.Identity': Z => { Z.Comonad.test (Identity (0)); },
'test.Contravariant.Function': Z => { Z.Contravariant.test (Math.abs); },
}));
Loading