diff options
Diffstat (limited to 'src/gleam_stdlib.js')
-rw-r--r-- | src/gleam_stdlib.js | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/gleam_stdlib.js b/src/gleam_stdlib.js index 479b8a9..b63a4ea 100644 --- a/src/gleam_stdlib.js +++ b/src/gleam_stdlib.js @@ -189,6 +189,25 @@ export function bit_string_append(first, second) { return array; } +function reduce_list(list, acc, f) { + let [current, next] = list; + while (next) { + acc = f(acc, current); + [current, next] = next; + } + return acc; +} + +export function bit_string_concat(bit_strings) { + let size = reduce_list(bit_strings, 0, (size, b) => b.byteLength + size); + let array = new Uint8Array(size); + reduce_list(bit_strings, 0, (index, bit_string) => { + array.set(bit_string, index); + return index + bit_string.byteLength; + }); + return array; +} + export function log(term) { console.log(term); } |