Skip to content

unzipWith (関数型プログラミング)

zip された配列を位置ごとに再グループ化し、各位置を結合する関数を作成します。関数型プログラミングの pipe と一緒に使用します。

typescript
const result = pipe(array, unzipWith(iteratee));

INFO

パイプラインとして組み合わせない通常のコードでは、元の es-toolkit の unzipWith を使うのがおすすめです。pipe で変換をつなげるときは、この fp 版を使用してください。

使用法

unzipWith はグループ化された行から同じ位置の値を集め、iteratee に渡して、その結果を返します。

typescript
import { pipe, unzipWith } from 'es-toolkit/fp';

pipe(
  [
    [1, 10],
    [2, 20],
  ],
  unzipWith((a, b) => a + b)
); // => [3, 30]

パラメータ

  • iteratee ((...args: T[]) => R): 同じ位置の値を結合する関数です。

戻り値

((target: readonly T[][]) => R[]): zip された行を位置ごとの結合結果に変換する関数です。

MIT ライセンスの下で配布されています。