pluck() function
提供された Iterable/AsyncIterable 内のすべてのオブジェクトから同じ名前のプロパティを取り出して Iterable/AsyncIterable を返します。
Signature:
typescript
declare function pluck<O extends object, K extends keyof O>(
key: K,
iterable: Iterable<O>,
): IterableIterator<O[K]>;Example
ts
const iter = pluck("age", [{ age: 21 }, { age: 22 }, { age: 23 }]);
iter.next(); // {done:false, value: 21}
iter.next(); // {done:false, value: 22}
iter.next(); // {done:false, value: 23}
// with pipe
pipe([{ age: 21 }, { age: 22 }, { age: 23 }], pluck("age"), toArray); // [21, 22 ,23]
// if you want to use asynchronous callback
await pipe(
Promise.resolve([{ age: 21 }, { age: 22 }, { age: 23 }]),
toAsync,
pluck("age"),
toArray,
); // [21, 22 ,23]
// with toAsync
await pipe(
[
Promise.resolve({ age: 21 }),
Promise.resolve({ age: 22 }),
Promise.resolve({ age: 23 }),
],
toAsync,
pluck("age"),
toArray,
); // [21, 22 ,23]