Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Named version of `mapN` and friends

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

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
35/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
停滞
技术栈
scala

调研方向

首先阅读 issue 中链接的 Scala 3 Named Tuples 和 Structural Types 文档,然后查找 Cats 现有的 mapN 和 parMapN API。issue 没有指定文件或测试;要完成这项工作,需要确定一个用于命名 applicative 组合的 Scala 3 API,并进行相应的验证。

由索引模型根据 Issue 内容生成。

描述

I wonder if we could have a Scala 3 only version of mapN and friends that work on NamedTuples instead of plain ones.

The motivation would be to fix the major usability issue with applicative composition, where operations and the names of their results are separated.

For example, imagine a very simple for comprehension like this:

final case class Config(foo: Foo, bar: Bar, baz: Baz, quax: Quax)
object Config {
  def load: IO[Config] =
    for {
      foo <- env(name = "FOO").as[Foo]
      bar <- env(name = "BAR").as[Bar]
      baz <- env(name = "BAZ").as[Baz]
      quax <- env(name = "QUAX").as[Quax]
    } yield Config(foo, bar, baz, quax)
}

One may realize that there is no dependency between each operation, and thus that instead of failing fast, we could try to read all env vars "concurrently" and accumulate all the errors instead:

def load: IO[Config] =
  (
    env(name = "FOO").as[Foo],
    env(name = "BAR").as[Bar],
    env(name = "BAZ").as[Baz],
    env(name = "QUAX").as[Quax]
  ).parMapN { case (foo, bar, baz, quax) =>
    Config(foo, bar, baz, quax)
  }

But, this disconnects the names (foo, bar, baz, quax) from the operations that produced them; and yes, in this case, you could just do parMapN(Config.apply) but that is besides the point.

Thus, it would be great if we could use NamedTuples and maybe Structural Types to get an API like this:

def load: IO[Config] =
  (
    foo = env(name = "FOO").as[Foo],
    bar = env(name = "BAR").as[Bar],
    baz = env(name = "BAZ").as[Baz],
    quax = env(name = "QUAX").as[Quax]
  ).namedParMapN { result =>
    Config(result.foo, result.bar, result.baz, result.quax)
  }
主要语言
Scala
星标
5.5k
派生
1.2k
平均合并
4 天 6 小时
30 天内合并 PR
6

环境准备

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

从这里开始

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

typelevel/cats 的其他 Issue

查看 typelevel/cats 的全部 Issue

相似的 Issue

更多 Scala Issue

把新 issue 发到你的邮箱

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