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

Restruct functor #1934

Merged
merged 3 commits into from
Oct 2, 2017
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package cats
package functor

import simulacrum.typeclass

/**
* A type class of types which give rise to two independent, covariant
* functors.
Expand Down Expand Up @@ -58,7 +55,7 @@ import simulacrum.typeclass
}

private[cats] trait ComposedBifunctor[F[_, _], G[_, _]]
extends Bifunctor[λ[(A, B) => F[G[A, B], G[A, B]]]] {
extends Bifunctor[λ[(A, B) => F[G[A, B], G[A, B]]]] {
def F: Bifunctor[F]
def G: Bifunctor[G]

Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/cats/Bitraverse.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package cats

import cats.functor.{Bifunctor, ComposedBifunctor}


import simulacrum.typeclass

Expand Down
1 change: 0 additions & 1 deletion core/src/main/scala/cats/Composed.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package cats

import cats.functor._

private[cats] trait ComposedInvariant[F[_], G[_]] extends Invariant[λ[α => F[G[α]]]] { outer =>
def F: Invariant[F]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package cats
package functor

import simulacrum.typeclass

/**
* Must obey the laws defined in cats.laws.ContravariantLaws.
*/
Expand Down
1 change: 0 additions & 1 deletion core/src/main/scala/cats/ContravariantCartesian.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package cats

import functor.Contravariant
import simulacrum.typeclass

/**
Expand Down
6 changes: 2 additions & 4 deletions core/src/main/scala/cats/Functor.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package cats

import cats.functor.Contravariant

import simulacrum.typeclass

/**
Expand All @@ -11,10 +9,10 @@ import simulacrum.typeclass
*
* Must obey the laws defined in cats.laws.FunctorLaws.
*/
@typeclass trait Functor[F[_]] extends functor.Invariant[F] { self =>
@typeclass trait Functor[F[_]] extends Invariant[F] { self =>
def map[A, B](fa: F[A])(f: A => B): F[B]

def imap[A, B](fa: F[A])(f: A => B)(fi: B => A): F[B] = map(fa)(f)
override def imap[A, B](fa: F[A])(f: A => B)(g: B => A): F[B] = map(fa)(f)

// derived methods

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package cats
package functor

import simulacrum.typeclass

/**
* Must obey the laws defined in cats.laws.InvariantLaws.
*/
Expand Down
1 change: 0 additions & 1 deletion core/src/main/scala/cats/InvariantMonoidal.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package cats

import cats.functor.Invariant
import simulacrum.typeclass

/**
Expand Down
2 changes: 0 additions & 2 deletions core/src/main/scala/cats/Show.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package cats

import cats.functor.Contravariant

/**
* A type class to provide textual representation. It is meant to be a
* better "toString". Whereas toString exists for any Object,
Expand Down
2 changes: 0 additions & 2 deletions core/src/main/scala/cats/arrow/Arrow.scala
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package cats
package arrow

import cats.functor.Strong

import simulacrum.typeclass

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package cats
package functor
package arrow

import simulacrum.typeclass

Expand All @@ -17,7 +17,7 @@ import simulacrum.typeclass
* Example:
* {{{
* scala> import cats.implicits._
* scala> import cats.functor.Profunctor
* scala> import cats.arrow.Profunctor
* scala> val fab: Double => Double = x => x + 0.3
* scala> val f: Int => Double = x => x.toDouble / 2
* scala> val g: Double => Double = x => x * 3
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package cats
package functor
package arrow

import simulacrum.typeclass

Expand All @@ -14,7 +14,7 @@ import simulacrum.typeclass
* Example:
* {{{
* scala> import cats.implicits._
* scala> import cats.functor.Strong
* scala> import cats.arrow.Strong
* scala> val f: Int => Int = _ * 2
* scala> val fab = Strong[Function1].first[Int,Int,Int](f)
* scala> fab((2,3))
Expand All @@ -29,7 +29,7 @@ import simulacrum.typeclass
* Example:
* {{{
* scala> import cats.implicits._
* scala> import cats.functor.Strong
* scala> import cats.arrow.Strong
* scala> val f: Int => Int = _ * 2
* scala> val fab = Strong[Function1].second[Int,Int,Int](f)
* scala> fab((2,3))
Expand Down
6 changes: 3 additions & 3 deletions core/src/main/scala/cats/data/Cokleisli.scala
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package cats
package data

import cats.arrow.{Arrow, Category, CommutativeArrow, Compose}
import cats.functor.{Contravariant, Profunctor}
import cats.{CoflatMap, Comonad, Functor, Monad}
import cats.arrow._
import cats.{CoflatMap, Comonad, Contravariant, Functor, Monad}

import scala.annotation.tailrec

/**
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/cats/data/Const.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package cats
package data

import cats.functor.Contravariant
import cats.Contravariant

/**
* [[Const]] is a phantom type, it does not contain a value of its second type parameter `B`
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/cats/data/EitherK.scala
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package cats
package data

import cats.Contravariant
import cats.arrow.FunctionK
import cats.functor.Contravariant
import cats.syntax.either._

/** `F` on the left and `G` on the right of `scala.util.Either`.
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/scala/cats/data/EitherT.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package cats
package data

import cats.functor.Bifunctor
import cats.Bifunctor
import cats.instances.either._
import cats.syntax.either._

Expand Down Expand Up @@ -426,7 +426,7 @@ private[data] abstract class EitherTInstances extends EitherTInstances1 {
}

implicit def catsDataShowForEitherT[F[_], L, R](implicit sh: Show[F[Either[L, R]]]): Show[EitherT[F, L, R]] =
functor.Contravariant[Show].contramap(sh)(_.value)
Contravariant[Show].contramap(sh)(_.value)

implicit def catsDataBifunctorForEitherT[F[_]](implicit F: Functor[F]): Bifunctor[EitherT[F, ?, ?]] =
new Bifunctor[EitherT[F, ?, ?]] {
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/cats/data/Func.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package cats
package data

import cats.functor.Contravariant
import cats.Contravariant

/**
* [[Func]] is a function `A => F[B]`.
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/cats/data/IdT.scala
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,6 @@ private[data] sealed abstract class IdTInstances extends IdTInstances0 {
F.on(_.value)

implicit def catsDataShowForIdT[F[_], A](implicit F: Show[F[A]]): Show[IdT[F, A]] =
functor.Contravariant[Show].contramap(F)(_.value)
Contravariant[Show].contramap(F)(_.value)

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package cats
package data

import cats.functor.{ Bifunctor, Contravariant, Profunctor, Strong }
import cats.arrow.{Profunctor, Strong}

import cats.syntax.either._

/**
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/scala/cats/data/IndexedStateT.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package cats
package data

import cats.functor.{ Contravariant, Bifunctor, Profunctor, Strong }
import cats.arrow.{Profunctor, Strong}

import cats.syntax.either._

/**
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/cats/data/Ior.scala
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package cats
package data

import cats.Bifunctor
import cats.data.Validated.{Invalid, Valid}
import cats.functor.Bifunctor

import scala.annotation.tailrec

Expand Down
4 changes: 2 additions & 2 deletions core/src/main/scala/cats/data/Kleisli.scala
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package cats
package data

import cats.arrow.{Arrow, Category, Choice, CommutativeArrow, Compose, FunctionK}
import cats.functor.{Contravariant, Strong}
import cats.Contravariant
import cats.arrow._

/**
* Represents a function `A => F[B]`.
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/cats/data/Nested.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package cats
package data

import cats.functor._


/** Similar to [[cats.data.Tuple2K]], but for nested composition.
*
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/cats/data/OptionT.scala
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ private[data] sealed abstract class OptionTInstances extends OptionTInstances0 {
new OptionTOrder[F, A] { implicit val F = F0 }

implicit def catsDataShowForOptionT[F[_], A](implicit F: Show[F[Option[A]]]): Show[OptionT[F, A]] =
functor.Contravariant[Show].contramap(F)(_.value)
Contravariant[Show].contramap(F)(_.value)
}

private[data] sealed abstract class OptionTInstances0 extends OptionTInstances1 {
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/cats/data/Tuple2K.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package cats
package data

import cats.functor.Contravariant
import cats.Contravariant

/**
* [[Tuple2K]] is a product to two independent functor values.
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/cats/data/Validated.scala
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ sealed abstract class Validated[+E, +A] extends Product with Serializable {
Validated.fromEither(f(toEither))

/**
* Validated is a [[functor.Bifunctor]], this method applies one of the
* Validated is a [[Bifunctor]], this method applies one of the
* given functions.
*/
def bimap[EE, AA](fe: E => EE, fa: A => AA): Validated[EE, AA] =
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/cats/data/WriterT.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package cats
package data

import cats.kernel.instances.tuple._
import cats.functor.{Bifunctor, Contravariant}

import cats.kernel.CommutativeMonoid
import cats.syntax.semigroup._

Expand Down
5 changes: 3 additions & 2 deletions core/src/main/scala/cats/instances/function.scala
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package cats
package instances

import cats.arrow.{CommutativeArrow, Category, Choice}
import cats.functor.Contravariant
import cats.Contravariant
import cats.arrow.{Category, Choice, CommutativeArrow}

import annotation.tailrec


Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/cats/syntax/bifunctor.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package cats
package syntax

import cats.functor.Bifunctor
import cats.Bifunctor

trait BifunctorSyntax extends Bifunctor.ToBifunctorOps
2 changes: 1 addition & 1 deletion core/src/main/scala/cats/syntax/contravariant.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package cats
package syntax

import cats.functor.Contravariant
import cats.Contravariant

trait ContravariantSyntax extends Contravariant.ToContravariantOps

2 changes: 1 addition & 1 deletion core/src/main/scala/cats/syntax/invariant.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package cats
package syntax

import cats.functor.Invariant
import cats.Invariant

trait InvariantSyntax extends Invariant.ToInvariantOps
2 changes: 1 addition & 1 deletion core/src/main/scala/cats/syntax/profunctor.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package cats
package syntax

import cats.functor.Profunctor
import cats.arrow.Profunctor

trait ProfunctorSyntax extends Profunctor.ToProfunctorOps
2 changes: 1 addition & 1 deletion core/src/main/scala/cats/syntax/strong.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package cats
package syntax

import cats.functor.Strong
import cats.arrow.Strong

trait StrongSyntax extends Strong.ToStrongOps
4 changes: 2 additions & 2 deletions docs/src/main/tut/typeclasses/contravariant.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ layout: docs
title: "Contravariant"
section: "typeclasses"
source: "core/src/main/scala/cats/functor/Contravariant.scala"
scaladoc: "#cats.functor.Contravariant"
scaladoc: "#cats.Contravariant"
---
# Contravariant

Expand All @@ -28,7 +28,7 @@ Say we have class `Money` with a `Show` instance, and `Salary` class.

```tut:silent
import cats._
import cats.functor._

import cats.implicits._

case class Money(amount: Int)
Expand Down
2 changes: 1 addition & 1 deletion docs/src/main/tut/typeclasses/invariant.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ layout: docs
title: "Invariant"
section: "typeclasses"
source: "core/src/main/scala/cats/functor/Invariant.scala"
scaladoc: "#cats.functor.Invariant"
scaladoc: "#cats.Invariant"
---
# Invariant

Expand Down
2 changes: 1 addition & 1 deletion laws/src/main/scala/cats/laws/BifunctorLaws.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package cats.laws

import cats.functor.Bifunctor
import cats.Bifunctor
import cats.syntax.bifunctor._

/**
Expand Down
4 changes: 2 additions & 2 deletions laws/src/main/scala/cats/laws/ContravariantLaws.scala
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package cats
package laws

import cats.functor.Contravariant
import cats.Contravariant
import cats.syntax.contravariant._

/**
* Laws that must be obeyed by any `cats.functor.Contravariant`.
* Laws that must be obeyed by any `cats.Contravariant`.
*/
trait ContravariantLaws[F[_]] extends InvariantLaws[F] {
implicit override def F: Contravariant[F]
Expand Down
Loading