@@ -543,5 +543,42 @@ object messages {
543
543
|
544
544
| """ .stripMargin
545
545
}
546
-
546
+
547
+ case class ProperDefinitionNotFound ()(implicit ctx : Context ) extends Message (20 ) {
548
+ val kind = " Definition Not Found"
549
+ val msg = hl """ |Proper definition was not found in ${" @usecase" }"""
550
+
551
+ val noUsecase = " def map[B, That](f: A => B)(implicit bf: CanBuildFrom[List[A], B, That]): That"
552
+
553
+ val usecase =
554
+ """ |/** Map from List[A] => List[B]
555
+ | *
556
+ | * @usecase def map[B](f: A => B): List[B]
557
+ | */
558
+ |def map[B, That](f: A => B)(implicit bf: CanBuildFrom[List[A], B, That]): That""" .stripMargin
559
+
560
+ val explanation = {
561
+ hl """ | ${" @usecase" } are only supported for ${" def" }s. They exist because with Scala's
562
+ |advanced type-system, we sometimes end up with seemingly scary signatures.
563
+ |
564
+ |Let's see an example using the `map`function:
565
+ |
566
+ | ${" List(1, 2, 3).map(2 * _) // res: List(2, 4, 6)" }
567
+ |
568
+ |It's very straight forward to understand and use, but has such a scary signature:
569
+ |
570
+ | $noUsecase
571
+ |
572
+ |In order to mitigate this and ease the usage of such functions we have the ${" @usecase" }
573
+ |annotation for docstrings. Which can be used like this:
574
+ |
575
+ | $usecase
576
+ |
577
+ |Now when creating the docs, the method signature is substituted by the
578
+ | ${" @usecase" } with a reader-friendly version. The compiler makes sure that it is valid.
579
+ |
580
+ |Because of this, you must use ${" def" } when defining ${" @usecase" }. """ .stripMargin
581
+ }
582
+ }
583
+
547
584
}
0 commit comments