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

未关闭
#6,732 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

  • #6733 来自 @lionel-rowe —— 已关闭,未合并

评估

难度
4/5
预计耗时
3-5 天
新手友好度
35/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
停滞
技术栈
typescript

调研方向

定位 @std/collections 的 zip 入口点及其测试;先阅读当前的可变参数签名和现有行为。完成标准是:options 形式可以选择使用 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

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

denoland/std 的其他 Issue

查看 denoland/std 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。