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

예시 1: 배열에서 사용

import { find } from 'mori-ts';

const array = [1, 2, 3, 4, 5];

const result = find(x => x > 2, array);

console.log(result); // 출력: 3

예시 2: 비동기 iterable에서 사용

import { find } from 'mori-ts';

const result = find(x => x > 5, [1, 2, 3, 4, 5]);

console.log(result); // 출력: undefined

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

import { pipe, map, find, toAsync } from 'mori-ts';

const iter = [1, 2, 3, 4, 5];

const result = pipe(
  iter,
  map(x => x * 2),
  find(x => x > 5),
);

console.log(result); // 출력: 6

const result2 = await pipe(
  iter,
  toAsync,
  map(x => x * 2),
  find(x => x > 5),
);

console.log(result); // 출력: 6

테스트 코드 링크

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

Clone this wiki locally