Scaladoc [用例]

发布于 2024-09-30 11:19:23 字数 147 浏览 0 评论 0原文

为什么 Scaladoc 中的某些方法描述以 [use case] 开头?

示例: scala.collection.immutable.StringOps.++

它只是一个将来要替换的占位符吗?

Why do some method descriptions in Scaladoc start with [use case]?

Example: scala.collection.immutable.StringOps.++

Is it just a placeholder to be replaced in the future?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

还不是爱你 2024-10-07 11:19:23

它们是如何调用这些方法的简化示例。通常这些方法(++mapflatMap 等)包含一个隐式参数,最常见的是一个称为构建器工厂的参数,它(简而言之)抽象了结果集合的创建。

在大多数情况下,集合的客户端不会指定这些隐式参数,因此 ScalaDoc 允许定义方法的简化描述 - 用例。这使用户能够快速了解​​相关方法背后的想法,而不必担心 CanBuildFrom 的含义及其使用方式。

例如,这是 ++ 的完整声明:

def ++[B >: A, That](that: TraversableOnce[B])(implicit bf: CanBuildFrom[Repr, B, That]): That

在大多数情况下,目标集合类型与调用的接收者相同,因此调用看起来就像声明如下(假设 ++ 是在 List 上定义的):

def ++(that: TraversableOnce[A]): List[A]

上面,隐式在编译时被解析,并且类型参数被推断。在大多数情况下,这应该是客户对该方法的看法。

如果您想用用例注释您自己的方法,请在文档注释中使用 @usecase 标记:

/** ...
 *  ...
 *  @usecase def ++(that: TraversableOnce[A]): List[A]
 */

They are simplified examples of how these methods are called. Usually these methods (++, map, flatMap, etc.) contain an implicit parameter, most often an argument called a builder factory which (simply put) abstracts creation of resulting collections.

In most cases, a client of a collection does not specify these implicit parameters, so ScalaDoc allows defining a simplified description of the method - a use case. This enables users to quickly pick up the idea behind the method in question, and not be bothered with what e.g. CanBuildFrom means and how it's used.

For example, this is the full declaration of ++:

def ++[B >: A, That](that: TraversableOnce[B])(implicit bf: CanBuildFrom[Repr, B, That]): That

In most cases, the target collection type is the same as the receiver of the call, so the call pretty much looks as if the declaration is the following (assuming ++ is defined on a, say, List):

def ++(that: TraversableOnce[A]): List[A]

Above, the implicit is resolved at compile time, and the type parameters are inferred. In most cases, this should be the client's view of the method.

And if you want to annotate your own method with use cases, use the @usecase tag in your doc comments:

/** ...
 *  ...
 *  @usecase def ++(that: TraversableOnce[A]): List[A]
 */
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文