Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
812 views
in Technique[技术] by (71.8m points)

scala - Scaladoc [use case]

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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]
 */

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...