Skip to content

Commit

Permalink
use ES6 syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
davidchambers committed Apr 25, 2021
1 parent d79feb1 commit db087cc
Show file tree
Hide file tree
Showing 11 changed files with 948 additions and 1,121 deletions.
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

0 comments on commit db087cc

Please sign in to comment.