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 #732

Merged
merged 1 commit into from
Dec 8, 2023
Merged

use ES6 syntax #732

merged 1 commit into from
Dec 8, 2023

Conversation

davidchambers
Copy link
Member

@davidchambers davidchambers requested a review from Avaq December 8, 2023 13:31
index.js Outdated
}),
{env} // see S.env doctest
);
[Descending, Nil, Cons, Sum, S];
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These identifiers would otherwise only be referenced in doctests. Referencing them here avoids lint errors.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe warrants a comment

Comment on lines -3582 to +3364
function zipWith(f) {
return function(xs) {
return function(ys) {
var result = [];
var len = Math.min (xs.length, ys.length);
for (var idx = 0; idx < len; idx += 1) {
result.push (f (xs[idx]) (ys[idx]));
}
return result;
};
};
}
const zipWith = f => xs => ys => {
const result = new Array (Math.min (xs.length, ys.length));
for (let idx = 0; idx < result.length; idx += 1) {
result[idx] = f (xs[idx]) (ys[idx]);
}
return result;
};
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made a small optimization: calculating the length of the array up front.

Comment on lines -3887 to 3636
function values(strMap) {
return Z.map (function(k) { return strMap[k]; }, Object.keys (strMap));
}
_.values = {
consts: {},
types: [$.StrMap (a), $.Array (a)],
impl: values
impl: Object.values,
};
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I simplified this implementation. ;)

Comment on lines -4409 to +4126
function match(pattern) {
return function(s) {
return Z.map (function(m) { return Z.map (toMaybe, m.slice (1)); },
toMaybe (s.match (pattern)));
};
function toMaybe(x) { return x == null ? Nothing : Just (x); }
}
const match = pattern => s => {
const match = s.match (pattern);
if (match == null) return Nothing;
const groups = new Array (match.length - 1);
for (let idx = 0; idx < groups.length; idx += 1) {
const group = match[idx + 1];
groups[idx] = group == null ? Nothing : Just (group);
}
return Just (groups);
};
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated match to match matchAll.

@davidchambers davidchambers merged commit 89066e4 into main Dec 8, 2023
3 checks passed
@davidchambers davidchambers deleted the davidchambers/es6 branch December 8, 2023 14:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants