Skip to content
김태헌 edited this page Sep 26, 2024 · 5 revisions

예시 1: 기본 사용법

import { zip } from 'mori-ts';

const result = zip([1, 2, 3], ['a', 'b', 'c']);
// 결과: [[1, 'a'], [2, 'b'], [3, 'c']]

예시 2: 길이가 다른 배열

import { zip } from 'mori-ts';

const result1 = zip([1, 2, 3], ['a', 'b']);
// 결과: [[1, 'a'], [2, 'b']]

const result2 = zip([1, 2], ['a', 'b', 'c']);
// 결과: [[1, 'a'], [2, 'b']]

예시 3: 파이프라인과 함께 사용

import { zip, pipe, toArray, toAsync } from 'mori-ts';

const iter1 = [1, 2, 3];
const iter2 = ['a', 'b', 'c'];

const res = pipe(iter2, zip(iter1), toArray);
// 결과: [[1, 'a'], [2, 'b'], [3, 'c']]

const res2 = pipe(iter2, toAsync, zip(iter1), toArray);
// 결과: [[1, 'a'], [2, 'b'], [3, 'c']]

테스트 코드 링크

https://github.com/gangnamssal/mori-ts/blob/main/src/test/zip.spec.ts

Clone this wiki locally