@std/collections `zip` with customizable handling of where to truncate (longest vs shortest)

オープン
#6,732 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

  • #6733 @lionel-rowe による — マージされずにクローズ

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
35/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
typescript

調査の方向性

@std/collections の zip エントリーポイントとそのテストを特定し、まず現在の可変長引数シグネチャと既存の挙動を確認してください。オプション形式で undefined によるパディングを伴う最長切り捨てを選択でき、既存の最短切り捨ての挙動を維持したうえで、両方のパスをカバーできれば完了です。

索引モデルが issue の本文から書いたものです。

説明

Is your feature request related to a problem? Please describe.

Sometimes it's useful to zip arrays together without truncating the shorter ones, instead filling with undefined.

Describe the solution you'd like

Allow passing an option such as options.truncate = 'longest' to continue zipping until the longest array ends, filling missing values with undefined.

Describe alternatives you've considered

Not really sure how best to add this to the current function signature, given the variadic ...arrays param.

One possible option would be taking options as an initial parameter, which could be detected at runtime with Array.isArray:

type ZipOptions = {
  truncate?: 'shortest' | 'longest';
}

export function zip<T extends unknown[], O extends ZipOptions>(
  options: O,
  ...arrays: { [K in keyof T]: ReadonlyArray<T[K]> }
): {
  [K in keyof T]: O extends { truncate: "longest" } ? T[K] | undefined : T[K];
}[];
export function zip<T extends unknown[]>(
  ...arrays: { [K in keyof T]: ReadonlyArray<T[K]> }
): T[];
export function zip(
  ...args: unknown[]
): unknown[] {
  const [options, arrays] = args.length === 0 || Array.isArray(args[0]) ?
    [{}, args as unknown[][]] :
    [args[0] as ZipOptions, args.slice(1) as unknown[][]];

Otherwise, it might need to be a separate zipWithOptions function.

主要言語
TypeScript
スター
3.6k
フォーク
713
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

denoland/std のほかの issue

denoland/std の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。