map() function
각 요소에 f를 적용하여 실행한 값들의 Iterable/AsyncIterable을 반환합니다.
map이 부작용을 일으키는 경우 대신 mapEffect를 사용하는 것이 좋습니다.
Signature:
typescript
declare function map<A, B>(
f: (a: A) => B,
iterable: Iterable<A>,
): IterableIterator<B>;Example
ts
const iter = map((a) => a + 10, [1, 2, 3, 4]);
iter.next(); // {done:false, value: 11}
iter.next(); // {done:false, value: 12}
iter.next(); // {done:false, value: 13}
iter.next(); // {done:false, value: 14},
iter.next(); // {done:true, value: undefined}
// with pipe
pipe(
[1, 2, 3, 4],
map((a) => a + 10),
toArray,
); // [11, 12, 13, 14]
await pipe(
Promise.resolve([1, 2, 3, 4]),
map((a) => a + 10),
toArray,
); // [11, 12, 13, 14]
// if you want to use asynchronous callback
await pipe(
Promise.resolve([1, 2, 3, 4]),
toAsync,
map(async (a) => a + 10),
toArray,
); // [11, 12, 13, 14]
// with toAsync
await pipe(
[
Promise.resolve(1),
Promise.resolve(2),
Promise.resolve(3),
Promise.resolve(4),
],
toAsync,
map((a) => a + 10),
toArray,
); // [11, 12, 13, 14]