-
Notifications
You must be signed in to change notification settings - Fork 0
concat
김태헌 edited this page Sep 26, 2024
·
7 revisions
import { concat, toArray } from 'mori-ts';
const array1 = [1, 2, 3];
const array2 = [4, 5, 6];
const array3 = [7, 8, 9];
const result = concat(array1, array2, array3);
console.log([...result]); // 출력: [1, 2, 3, 4, 5, 6, 7, 8, 9]
console.log(toArray(result)); // 출력: [1, 2, 3, 4, 5, 6, 7, 8, 9]
const iterator = concat(array1, array2, array3);
console.log(iterator.next().value); // 출력: 1
console.log(iterator.next().value); // 출력: 2
console.log(iterator.next().value); // 출력: 3
console.log(iterator.next().value); // 출력: 4
console.log(iterator.next().value); // 출력: 5
console.log(iterator.next().value); // 출력: 6
console.log(iterator.next().value); // 출력: 7
console.log(iterator.next().value); // 출력: 8
console.log(iterator.next().value); // 출력: 9
console.log(iterator.next().done); // 출력: true
import { concat, toArray } from 'mori-ts';
const array1 = [1, 2, 3];
const array2 = [{ a: 1 }, { a: 2 }, { a: 3 }];
const array3 = [];
const array4 = ['a', 'b', 'c'];
const result = concat(array1, array2, array3);
console.log([...result]); // 출력: [1, 2, 3, { a: 1 }, { a: 2 }, { a: 3 }]
console.log(toArray(result)); // 출력: [1, 2, 3, { a: 1 }, { a: 2 }, { a: 3 }]
const result2 = concat(array1, array3, array4);
console.log([...result2]); // 출력: [1, 2, 3, 'a', 'b', 'c']
console.log(toArray(result2)); // 출력: [1, 2, 3, 'a', 'b', 'c']
import { concat, pipe, toArray, map } from 'mori-ts';
const iter1 = [1, 2, 3];
const iter2 = [4, 5, 6];
const res = pipe(
concat(iter1, iter2),
map(x => x * 2),
toArray,
);
console.log(res); // 출력: [2, 4, 6, 8, 10, 12]
https://github.com/gangnamssal/mori-ts/blob/main/src/test/concat.spec.ts