Skip to content

Commit

Permalink
type safe concat
Browse files Browse the repository at this point in the history
  • Loading branch information
uriva committed Aug 23, 2023
1 parent 621165e commit dd56636
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src/array.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
all,
any,
anymap,
concat,
contains,
drop,
enumerate,
Expand All @@ -17,6 +18,19 @@ import {

import { assertEquals } from "https://deno.land/std@0.174.0/testing/asserts.ts";

const _: number[] = concat([[1, 2, 3], [0, 0, 0]]);

Deno.test("concat", () => {
assertEquals(concat([[1, 2, 3], [0, 0, 0]]), [
1,
2,
3,
0,
0,
0,
]);
});

Deno.test("zip", () => {
assertEquals(zip([1, 2, 3], [0, 0, 0]), [
[1, 0],
Expand Down
2 changes: 1 addition & 1 deletion src/array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const unique = <T>(key: (x: T) => Primitive) => (array: T[]) => {
return result;
};

export const concat = (array: unknown[][]) => {
export const concat = <T>(array: T[][]) => {
const result = [];
for (const xs of array) {
for (const x of xs) {
Expand Down

0 comments on commit dd56636

Please sign in to comment.