Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleaning up docs to no longer use fine grained imports #2664

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/src/main/tut/datatypes/either.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ in the standard library. Since Cats builds on 2.10.x and 2.11.x, the gaps have b
enrichments available under `cats.syntax.either._` or `cats.implicits._`.

```tut:book
import cats.syntax.either._
import cats.implicits._

val right: Either[String, Int] = Right(5)
right.map(_ + 1)
Expand Down
2 changes: 1 addition & 1 deletion docs/src/main/tut/datatypes/ior.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ val both = Ior.both("Warning", 3)
Cats also offers syntax enrichment for `Ior`. The `leftIor` and `rightIor` functions can be imported from `cats.syntax.ior._`:

```tut
import cats.syntax.ior._
import cats.implicits._

val right = 3.rightIor

Expand Down
8 changes: 2 additions & 6 deletions docs/src/main/tut/datatypes/nested.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ x.map(_.map(_.toString))

```tut:silent
import cats.data.Nested
import cats.instances.option._
import cats.syntax.functor._
import cats.implicits._
val nested: Nested[Option, Validated[String, ?], Int] = Nested(Some(Valid(123)))
```

Expand Down Expand Up @@ -88,10 +87,7 @@ import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.duration._
import cats.Applicative
import cats.data.Nested
import cats.instances.either._
import cats.instances.future._
import cats.instances.list._
import cats.syntax.traverse._
import cats.implicits._

def createUsers(userInfos: List[UserInfo]): Future[Either[List[String], List[User]]] =
userInfos.traverse(userInfo => Nested(createUser(userInfo))).value
Expand Down
4 changes: 2 additions & 2 deletions docs/src/main/tut/datatypes/validated.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ case object AgeIsInvalid extends DomainValidation {
We have our `RegistrationData` case class that will hold the information the user has submitted, alongside the definition of the error model that we'll be using for displaying the possible errors of every field. Now, let's explore the proposed implementation:

```tut:silent
import cats.syntax.either._
import cats.implicits._

sealed trait FormValidator {
def validateUserName(userName: String): Either[DomainValidation, String] =
Expand Down Expand Up @@ -627,7 +627,7 @@ val houseNumber = config.parse[Int]("house_number").andThen{ n =>
The `withEither` method allows you to temporarily turn a `Validated` instance into an `Either` instance and apply it to a function.

```tut:silent
import cats.syntax.either._ // get Either#flatMap
import cats.implicits._ // get Either#flatMap

def positive(field: String, i: Int): Either[ConfigError, Int] = {
if (i >= 0) Right(i)
Expand Down
9 changes: 4 additions & 5 deletions docs/src/main/tut/typeclasses/applicative.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def product3[F[_]: Applicative, A, B, C](fa: F[A], fb: F[B], fc: F[C]): F[(A, B,
Let's see what happens if we try to compose two effectful values with just `map`.

```tut:book:silent
import cats.instances.option._
import cats.implicits._

val f: (Int, Char) => Double = (i, c) => (i + c).toDouble

Expand All @@ -109,7 +109,7 @@ does `F[G[_]]`.

```tut:book:silent
import cats.data.Nested
import cats.instances.future._
import cats.implicits._
import scala.concurrent.Future
import scala.concurrent.ExecutionContext.Implicits.global

Expand Down Expand Up @@ -181,7 +181,7 @@ This works...but if we look carefully at the implementation there's nothing `Opt
another example let's implement the same function but for `Either`.

```tut:book:silent
import cats.instances.either._
import cats.implicits._

def traverseEither[E, A, B](as: List[A])(f: A => Either[E, B]): Either[E, List[B]] =
as.foldRight(Right(List.empty[B]): Either[E, List[B]]) { (a: A, acc: Either[E, List[B]]) =>
Expand Down Expand Up @@ -212,8 +212,7 @@ This function is provided by Cats via the `Traverse[List]` instance and syntax,
tutorial.

```tut:book:silent
import cats.instances.list._
import cats.syntax.traverse._
import cats.implicits

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did this miss the ._?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops, missed that, I will fix that in a separate PR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why didn't this broke the build?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the import isn't really needed for the code since it's already imported at previous blocks. I guess unused import isn't checked in tut.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it is not needed I'd remove it or require that each paragraph needs to specify its imports again with maybe tut's :reset modifier.

Copy link
Contributor

@kailuowang kailuowang Dec 6, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I read the page again and I can see all these imports are confusing. It looks like it would be cumbersome to reset every paragraph.

I suggested that we remove import cats.implicits._ from them and add it to the top of the page, with something like:

First, bring cats instances into the scope by

import cats.implicits._

```

```tut:book
Expand Down
5 changes: 2 additions & 3 deletions docs/src/main/tut/typeclasses/functor.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ Such composition can be achieved via the `Functor#compose` method.

```tut:reset:book:silent
import cats.Functor
import cats.instances.list._
import cats.instances.option._
import cats.implicits._
```

```tut:book
Expand Down Expand Up @@ -96,7 +95,7 @@ We can make this nicer at the cost of boxing with the `Nested` data type.

```tut:book:silent
import cats.data.Nested
import cats.syntax.functor._
import cats.implicits._
```

```tut:book
Expand Down
6 changes: 3 additions & 3 deletions docs/src/main/tut/typeclasses/monoid.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def combineAll[A: Monoid](as: List[A]): A =
which can be used for any type that has a `Monoid` instance.

```tut:book:silent
import cats.instances.all._
import cats.implicits._
```

```tut:book
Expand Down Expand Up @@ -100,7 +100,7 @@ How then can we collapse a `List[NonEmptyList[A]]` ? For such types that only ha
lift into `Option` to get a `Monoid`.

```tut:book:silent
import cats.syntax.semigroup._
import cats.implicits._

implicit def optionMonoid[A: Semigroup]: Monoid[Option[A]] = new Monoid[Option[A]] {
def empty: Option[A] = None
Expand All @@ -124,7 +124,7 @@ Thus:
```tut:reset:book:silent
import cats.Monoid
import cats.data.NonEmptyList
import cats.instances.option._
import cats.implicits._

val list = List(NonEmptyList(1, List(2, 3)), NonEmptyList(4, List(5, 6)))
val lifted = list.map(nel => Option(nel))
Expand Down
9 changes: 4 additions & 5 deletions docs/src/main/tut/typeclasses/semigroup.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Semigroup[Int].combine(Semigroup[Int].combine(x, y), z)
Infix syntax is also available for types that have a `Semigroup` instance.

```tut:book
import cats.syntax.semigroup._
import cats.implicits._

1 |+| 2
```
Expand All @@ -56,7 +56,7 @@ A more compelling example which we'll see later in this tutorial is the `Semigro
for `Map`s.

```tut:book:silent
import cats.instances.map._
import cats.implicits._

val map1 = Map("hello" -> 0, "world" -> 1)
val map2 = Map("hello" -> 2, "cats" -> 3)
Expand All @@ -74,7 +74,7 @@ Cats provides many `Semigroup` instances out of the box such as `Int` (`+`) and

```tut:reset:book:silent
import cats.Semigroup
import cats.instances.all._
import cats.implicits._
```

```tut:book
Expand Down Expand Up @@ -108,8 +108,7 @@ type say, `Int` or `List[String]`, but we can write it once and for all for
any type with a `Semigroup` instance.

```tut:book:silent
import cats.instances.all._
import cats.syntax.semigroup._
import cats.implicits._

def optionCombine[A: Semigroup](a: A, opt: Option[A]): A =
opt.map(a |+| _).getOrElse(a)
Expand Down
4 changes: 1 addition & 3 deletions docs/src/main/tut/typeclasses/traverse.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,7 @@ a `List[Option[A]]`. Since the values themselves are effects, traversing with `i
will turn the traversable "inside out."

```tut:reset:book:silent
import cats.instances.list._
import cats.instances.option._
import cats.syntax.traverse._
import cats.implicits._
```

```tut:book
Expand Down