aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLouis Pilfold <louis@lpil.uk>2023-06-22 16:59:45 +0100
committerLouis Pilfold <louis@lpil.uk>2023-06-22 16:59:45 +0100
commit72f45419de67adfb9acc517c7510859592281f4a (patch)
treec05d57d825c4241c993697925473e4cd1711c79e
parent6a097950fb48ece2a825aee33d043624967e8b76 (diff)
downloadgleam_stdlib-72f45419de67adfb9acc517c7510859592281f4a.tar.gz
gleam_stdlib-72f45419de67adfb9acc517c7510859592281f4a.zip
Slightly more concise
-rw-r--r--src/gleam_stdlib.mjs51
1 files changed, 24 insertions, 27 deletions
diff --git a/src/gleam_stdlib.mjs b/src/gleam_stdlib.mjs
index 6af9aff..a2fbaa6 100644
--- a/src/gleam_stdlib.mjs
+++ b/src/gleam_stdlib.mjs
@@ -197,15 +197,12 @@ export function split(xs, pattern) {
}
export function join(xs, separator) {
- let result = "";
- let i = 0;
- for (const x of xs) {
- if (i == 0) {
- result = x
- } else {
- result = result + separator + x;
- }
- i++;
+ const iterator = xs[Symbol.iterator]();
+ let result = iterator.next().value || "";
+ let current = iterator.next();
+ while (!current.done) {
+ result = result + separator + current.value;
+ current = iterator.next();
}
return result;
}
@@ -515,14 +512,14 @@ function uint6ToB64(nUint6) {
return nUint6 < 26
? nUint6 + 65
: nUint6 < 52
- ? nUint6 + 71
- : nUint6 < 62
- ? nUint6 - 4
- : nUint6 === 62
- ? 43
- : nUint6 === 63
- ? 47
- : 65;
+ ? nUint6 + 71
+ : nUint6 < 62
+ ? nUint6 - 4
+ : nUint6 === 62
+ ? 43
+ : nUint6 === 63
+ ? 47
+ : 65;
}
// From https://developer.mozilla.org/en-US/docs/Glossary/Base64#Solution_2_%E2%80%93_rewrite_the_DOMs_atob()_and_btoa()_using_JavaScript's_TypedArrays_and_UTF-8
@@ -530,14 +527,14 @@ function b64ToUint6(nChr) {
return nChr > 64 && nChr < 91
? nChr - 65
: nChr > 96 && nChr < 123
- ? nChr - 71
- : nChr > 47 && nChr < 58
- ? nChr + 4
- : nChr === 43
- ? 62
- : nChr === 47
- ? 63
- : 0;
+ ? nChr - 71
+ : nChr > 47 && nChr < 58
+ ? nChr + 4
+ : nChr === 43
+ ? 62
+ : nChr === 47
+ ? 63
+ : 0;
}
// From https://developer.mozilla.org/en-US/docs/Glossary/Base64#Solution_2_%E2%80%93_rewrite_the_DOMs_atob()_and_btoa()_using_JavaScript's_TypedArrays_and_UTF-8
@@ -660,7 +657,7 @@ function decode_tupleN(data, n) {
return new Ok(data);
}
- let list = decode_exact_length_list(data, n);
+ const list = decode_exact_length_list(data, n);
if (list) return new Ok(list);
return decoder_error(`Tuple of ${n} elements`, data);
@@ -669,7 +666,7 @@ function decode_tupleN(data, n) {
function decode_exact_length_list(data, n) {
if (!List.isList(data)) return;
- let elements = [];
+ const elements = [];
let current = data;
for (let i = 0; i < n; i++) {