-
-
Notifications
You must be signed in to change notification settings - Fork 95
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
use ES6 syntax #732
Conversation
index.js
Outdated
}), | ||
{env} // see S.env doctest | ||
); | ||
[Descending, Nil, Cons, Sum, S]; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe warrants a comment
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; | ||
}; |
There was a problem hiding this comment.
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.
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, | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I simplified this implementation. ;)
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); | ||
}; |
There was a problem hiding this comment.
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
.
9c3a53b
to
9baf9f7
Compare
#687