Skip to content

Commit 1a0d029

Browse files
authored
Merge pull request #4613 from performantdata/documentation
correct & add documentation links
2 parents 17d7e95 + 531ed53 commit 1a0d029

File tree

2 files changed

+37
-36
lines changed

2 files changed

+37
-36
lines changed

core/src/main/scala/cats/package.scala

+27-23
Original file line numberDiff line numberDiff line change
@@ -26,32 +26,36 @@ import cats.data.Ior
2626
* The `cats` root package contains all the trait signatures of most Scala type classes.
2727
*
2828
* Cats type classes are implemented using the approach from the
29-
* [[https://ropas.snu.ac.kr/~bruno/papers/TypeClasses.pdf Type classes as objects and implicits]] article.
29+
* "[[https://i.cs.hku.hk/~bruno/papers/TypeClasses.pdf Type classes as objects and implicits]]" article.
3030
*
31-
* For each type class, `cats` provides three pieces:
32-
* - Its '''signature''': a trait that is polymorphic on a type parameter.
33-
* Type class traits inherit from other type classes to indicate that any implementation of the lower type class (e.g. `Applicative`)
34-
* can also serve as an instance for the higher type class (e.g. `Functor`).
35-
* - Type class ''''instances''', which are classes and objects that implement one or more type class signatures for some specific types.
36-
* Type class instances for several data types from the Java or Scala standard libraries are declared in the subpackage `cats.instances`.
37-
* - '''Syntax extensions''', each of which provides the methods of the type class defines as extension methods
38-
* (which in Scala 2 are encoded as implicit classes) for values of any type `F`; given that an instance of the type class
39-
* for the receiver type (`this`) is in the implicit scope.
40-
* Syntax extensions are declared in the `cats.syntax` package.
41-
* - A set of '''laws''', that are also generic on the type of the class, and are only defined on the operations of the type class.
42-
* The purpose of these laws is to declare some algebraic relations (equations) between Scala expressions involving the operations
43-
* of the type class, and test (but not verify) that implemented instances satisfy those equations.
44-
* Laws are defined in the `cats-laws` package.
31+
* For each type class, `cats` provides four pieces:
32+
* - Its '''signature''': a trait that is polymorphic on a type parameter.
33+
* Type class traits inherit from other type classes to indicate that any implementation of the lower type class
34+
* (e.g. [[Applicative `Applicative`]])
35+
* can also serve as an instance for the higher type class (e.g. [[Functor `Functor`]]).
36+
* - Type class '''instances''', which are classes and objects that implement one or more type class signatures for some specific types.
37+
* Type class instances for several data types from the Java or Scala standard libraries are declared
38+
* in the subpackage [[cats.instances `cats.instances`]].
39+
* - '''Syntax extensions''', each of which provides the methods of the type class defined as extension methods
40+
* (which in Scala 2 are encoded as implicit classes) for values of any type `F`; given that an instance of the type class
41+
* for the receiver type (`this`) is in the implicit scope.
42+
* Syntax extensions are declared in the [[cats.syntax `cats.syntax`]] package.
43+
* - A set of '''laws''', that are also generic on the type of the class, and are only defined on the operations of the type class.
44+
* The purpose of these laws is to declare some algebraic relations (equations) between Scala expressions involving the operations
45+
* of the type class, and test (but not verify) that implemented instances satisfy those equations.
46+
* Laws are defined in the [[cats.laws `cats.laws`]] package.
4547
*
4648
* Although most of cats type classes are declared in this package, some are declared in other packages:
47-
* - type classes that operate on base types (kind `*`), and their implementations for standard library types,
48-
* are contained in `cats.kernel`, which is a different SBT project. However, they are re-exported from this package.
49-
* - type classes of kind `F[_, _]`, such as [[cats.arrow.Profunctor]]" or [[cats.arrow.Arrow]], which are relevant for
50-
* Functional Reactive Programming or optics, are declared in the `cats.arrow` package.
51-
* - Also, those type classes that abstract over (pure or impure) functional runtime effects are declared
52-
* in the [[https://typelevel.org/cats-effect/ cats-effect library]].
53-
* - Some type classes for which no laws can be provided are left out of the main road, in a small and dirty alley.
54-
* These are the `alleycats`.
49+
* - type classes that operate on base types (kind `*`), and their implementations for standard library types,
50+
* are contained in [[cats.kernel `cats.kernel`]], which is a different SBT project. However, they are re-exported from this package.
51+
* - type classes of kind `F[_, _]`,
52+
* such as [[cats.arrow.Profunctor `cats.arrow.Profunctor`]] or [[cats.arrow.Arrow `cats.arrow.Arrow`]],
53+
* which are relevant for
54+
* Functional Reactive Programming or optics, are declared in the [[cats.arrow `cats.arrow`]] package.
55+
* - Also, those type classes that abstract over (pure or impure) functional runtime effects are declared
56+
* in the [[https://typelevel.org/cats-effect/ cats-effect library]].
57+
* - Some type classes for which no laws can be provided are left out of the main road, in a small and dirty alley.
58+
* These are the [[alleycats `alleycats`]].
5559
*/
5660
package object cats {
5761

docs/typeclasses/applicativemonaderror.md

+10-13
Original file line numberDiff line numberDiff line change
@@ -261,16 +261,16 @@ With the methods that we will compose in place let's create a method that will
261261
compose the above methods using a for comprehension which
262262
interprets to a `flatMap`-`map` combination.
263263

264-
`getTemperatureFromByCoordinates` parameterized type
265-
`[F[_]:MonadError[*[_], String]` injects `F[_]` into `MonadError[*[_], String]`
264+
`getTemperatureByCoordinates`'s parameterized type
265+
`[F[_]:MonadError[*[_], String]` injects `F[_]` into `MonadError[*[_], String]`;
266266
thus if the "error type" you wish to use is `Either[String, *]`, the `Either`
267267
would be placed in the hole of `MonadError`, in this case,
268268
`MonadError[Either[String, *], String]`
269269

270-
`getTemperatureFromByCoordinates` accepts a `Tuple2` of `Int` and `Int`, and we
271-
return `F` which represents our `MonadError` which can be a type like `Either` or
272-
`Validated`. In the method, since either `getCityClosestToCoordinate` and
273-
`getTemperatureByCity` both return potential error types and they are monadic we can
270+
`getTemperatureByCoordinates` accepts a `Tuple2` of `Int` and `Int` and
271+
returns `F`, which represents our `MonadError`, which can be a type like `Either` or
272+
`Validated`. In the method, since `getCityClosestToCoordinate` and
273+
`getTemperatureByCity` both return potential error types and they are monadic, we can
274274
compose them with a for comprehension.
275275

276276
```scala mdoc:silent
@@ -280,17 +280,14 @@ def getTemperatureByCoordinates[F[_]: MonadError[*[_], String]](x: (Int, Int)):
280280
}
281281
```
282282

283-
Invoking `getTemperatureByCoordinates` we can call it with the following sample,
284-
which will return `78`.
285-
286-
NOTE: infix `->` creates a `Tuple2`. `1 -> "Bob"` is the same as `(1, "Bob")`
283+
We can call `getTemperatureByCoordinates` with the following sample, which will return `78`.
287284

288285
```scala mdoc:silent
289286
type MyEither[A] = Either[String, A]
290-
getTemperatureByCoordinates[MyEither](44 -> 93)
287+
getTemperatureByCoordinates[MyEither]((44, 93))
291288
```
292289

293-
With TypeLevel Cats, how you structure your methods is up to you, if you wanted to
290+
With TypeLevel Cats, how you structure your methods is up to you: if you wanted to
294291
create `getTemperatureByCoordinates` without a Scala
295292
[context bound](https://docs.scala-lang.org/tutorials/FAQ/context-bounds.html) for `MonadError`,
296293
but create an `implicit` parameter for your `MonadError` you can have access to some
@@ -302,7 +299,7 @@ specialized methods, like `raiseError`, to raise an error representation
302299
when things go wrong.
303300

304301
```scala mdoc:silent
305-
def getTemperatureFromByCoordinatesAlternate[F[_]](x: (Int, Int))(implicit me: MonadError[F, String]): F[Int] = {
302+
def getTemperatureByCoordinatesAlternate[F[_]](x: (Int, Int))(implicit me: MonadError[F, String]): F[Int] = {
306303
if (x._1 < 0 || x._2 < 0) me.raiseError("Invalid Coordinates")
307304
else for { c <- getCityClosestToCoordinate[F](x)
308305
t <- getTemperatureByCity[F](c) } yield t

0 commit comments

Comments
 (0)