Skip to content

Commit

Permalink
Renamed all the things
Browse files Browse the repository at this point in the history
  • Loading branch information
djspiewak committed Jun 1, 2020
1 parent 783e610 commit 6aa812a
Show file tree
Hide file tree
Showing 68 changed files with 754 additions and 811 deletions.
8 changes: 4 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
### Adding a new transformer typeclass

First thing is the set of operations, or the *signature*.
For example `FunctorTell[F, E]` has the signature `def tell(e: E): F[Unit]`.
For example `Tell[F, E]` has the signature `def tell(e: E): F[Unit]`.

Once you've got this down, you need to come up with a set of laws and a base typeclass.
These have to be worked out at the same time, because choosing base classes with more operations gives
Expand All @@ -17,10 +17,10 @@ To be continued.
### Adding a new transformer typeclass instance

The characteristic which transformer typeclasses have in common is that instances of them are
commonly lifted through transformer stacks. I.e., if you have an `ApplicativeAsk[E => ?]`, you can
have an `ApplicativeAsk[EitherT[E => ?, String, ?]]`; a so-called *inductive* instance of `ApplicativeAsk`,
commonly lifted through transformer stacks. I.e., if you have an `Ask[E => ?]`, you can
have an `Ask[EitherT[E => ?, String, ?]]`; a so-called *inductive* instance of `Ask`,
because the capability is not provided by `EitherT` itself but the "inner monad".

Because of this, there's an argument to be made that there's only one transformer
typeclass instance you should need to provide: that of the "innermost" monad, the one
that is actually implementing the typeclass operations.
that is actually implementing the typeclass operations.
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ package cats.mtl
import cats.{Applicative, Id}
import cats.data.{Kleisli, Reader}

private[mtl] trait LowPriorityApplicativeAskInstancesCompat {
implicit def applicativeAskForReader[E]: ApplicativeAsk[Reader[E, *], E] =
new ApplicativeAsk[Reader[E, *], E] {
private[mtl] trait LowPriorityAskInstancesCompat {
implicit def askForReader[E]: Ask[Reader[E, *], E] =
new Ask[Reader[E, *], E] {
val applicative = Applicative[Reader[E, *]]
def ask = Kleisli.ask[Id, E]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ package cats.mtl
import cats.{Applicative, Id}
import cats.data.{Kleisli, Reader}

private[mtl] trait LowPriorityApplicativeLocalInstancesCompat {
implicit def applicativeLocalForReader[E]: ApplicativeLocal[Reader[E, *], E] =
new ApplicativeLocal[Reader[E, *], E] {
private[mtl] trait LowPriorityLocalInstancesCompat {
implicit def localForReader[E]: Local[Reader[E, *], E] =
new Local[Reader[E, *], E] {
def local[A](f: E => E)(fa: Reader[E, A]) = fa.local(f)
val applicative = Applicative[Reader[E, *]]
def ask = Kleisli.ask[Id, E]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package cats.mtl
import cats.Id
import cats.data.Writer

private[mtl] trait LowPriorityFunctorListenInstancesCompat {
implicit def baseFunctorListenForWriter[L]: FunctorListen[Writer[L, *], L] =
new FunctorListenWriterT[Id, L] {}
private[mtl] trait LowPriorityListenInstancesCompat {
implicit def baseListenForWriter[L]: Listen[Writer[L, *], L] =
new ListenWriterT[Id, L] {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ package cats.mtl
import cats.{Functor, Monoid}
import cats.data.Writer

private[mtl] trait LowPriorityFunctorTellInstancesCompat {
implicit def functorTellForWriter[L: Monoid]: FunctorTell[Writer[L, *], L] =
new FunctorTell[Writer[L, *], L] {
private[mtl] trait LowPriorityTellInstancesCompat {
implicit def tellForWriter[L: Monoid]: Tell[Writer[L, *], L] =
new Tell[Writer[L, *], L] {
val functor = Functor[Writer[L, *]]
def tell(l: L) = Writer.tell[L](l)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@

package cats.mtl

private[mtl] trait LowPriorityApplicativeAskInstancesCompat
private[mtl] trait LowPriorityAskInstancesCompat
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ package cats.mtl

import cats.data.Reader

private[mtl] trait LowPriorityApplicativeLocalInstancesCompat
private[mtl] trait LowPriorityLocalInstancesCompat
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@

package cats.mtl

private[mtl] trait LowPriorityFunctorListenInstancesCompat
private[mtl] trait LowPriorityListenInstancesCompat
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@

package cats.mtl

private[mtl] trait LowPriorityFunctorTellInstancesCompat
private[mtl] trait LowPriorityTellInstancesCompat
57 changes: 27 additions & 30 deletions core/src/main/scala/cats/mtl/ApplicativeAsk.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ import cats.data.{Kleisli, ReaderWriterStateT => RWST}
import scala.annotation.implicitNotFound

/**
* `ApplicativeAsk[F, E]` lets you access an `E` value in the `F[_]` context.
* `Ask[F, E]` lets you access an `E` value in the `F[_]` context.
*
* Intuitively, this means that an `E` value is required as an input to get "out" of the `F[_]` context.
*
* `ApplicativeAsk[F, E]` has one external law:
* `Ask[F, E]` has one external law:
* {{{
* def askAddsNoEffects[A](fa: F[A]) = {
* (ask *> fa) <-> fa
* }
* }}}
*
* `ApplicativeAsk[F, E]` has one internal law:
* `Ask[F, E]` has one internal law:
* {{{
* def readerIsAskAndMap[A](f: E => A) = {
* ask.map(f) <-> reader(f)
Expand All @@ -42,79 +42,76 @@ import scala.annotation.implicitNotFound
*
*/
@implicitNotFound(
"Could not find an implicit instance of ApplicativeAsk[${F}, ${E}]. If you have a\nvalue of type ${E} in scope, or a way of computing one, you may want to construct\na value of type Kleisli for this call-site, rather than type ${F}. An example type:\n\n Kleisli[${F}, ${E}, *]\n\nIf you do not have an ${E} or a way of getting one, you should add\nan implicit parameter of this type to your function. For example:\n\n (implicit fask: ApplicativeAsk[${F}, ${E}}])\n")
trait ApplicativeAsk[F[_], E] extends Serializable {
"Could not find an implicit instance of Ask[${F}, ${E}]. If you have a\nvalue of type ${E} in scope, or a way of computing one, you may want to construct\na value of type Kleisli for this call-site, rather than type ${F}. An example type:\n\n Kleisli[${F}, ${E}, *]\n\nIf you do not have an ${E} or a way of getting one, you should add\nan implicit parameter of this type to your function. For example:\n\n (implicit fask: Ask[${F}, ${E}}])\n")
trait Ask[F[_], E] extends Serializable {
def applicative: Applicative[F]

def ask: F[E]

def reader[A](f: E => A): F[A] = applicative.map(ask)(f)
}

private[mtl] trait ApplicativeAskForMonadPartialOrder[F[_], G[_], E]
extends ApplicativeAsk[G, E] {
private[mtl] trait AskForMonadPartialOrder[F[_], G[_], E] extends Ask[G, E] {
val lift: MonadPartialOrder[F, G]
val F: ApplicativeAsk[F, E]
val F: Ask[F, E]

override def applicative = lift.monadG
override def ask = lift(F.ask)
}

private[mtl] trait LowPriorityApplicativeAskInstances
extends LowPriorityApplicativeAskInstancesCompat {
private[mtl] trait LowPriorityAskInstances extends LowPriorityAskInstancesCompat {

implicit def applicativeAskForMonadPartialOrder[F[_], G[_], E](
implicit def askForMonadPartialOrder[F[_], G[_], E](
implicit lift0: MonadPartialOrder[F, G],
F0: ApplicativeAsk[F, E]): ApplicativeAsk[G, E] =
new ApplicativeAskForMonadPartialOrder[F, G, E] {
F0: Ask[F, E]): Ask[G, E] =
new AskForMonadPartialOrder[F, G, E] {
val lift: MonadPartialOrder[F, G] = lift0
val F: ApplicativeAsk[F, E] = F0
val F: Ask[F, E] = F0
}
}

private[mtl] trait ApplicativeAskInstances extends LowPriorityApplicativeAskInstances {
private[mtl] trait AskInstances extends LowPriorityAskInstances {

implicit def applicativeAskForKleisli[F[_], E](
implicit F: Applicative[F]): ApplicativeAsk[Kleisli[F, E, *], E] =
ApplicativeLocal.baseApplicativeLocalForKleisli[F, E]
implicit def askForKleisli[F[_], E](implicit F: Applicative[F]): Ask[Kleisli[F, E, *], E] =
Local.baseLocalForKleisli[F, E]

implicit def applicativeAskForRWST[F[_], E, L, S](
implicit def askForRWST[F[_], E, L, S](
implicit F: Monad[F],
L: Monoid[L]): ApplicativeAsk[RWST[F, E, L, S, *], E] =
ApplicativeLocal.baseApplicativeLocalForRWST[F, E, L, S]
L: Monoid[L]): Ask[RWST[F, E, L, S, *], E] =
Local.baseLocalForRWST[F, E, L, S]
}

object ApplicativeAsk extends ApplicativeAskInstances {
object Ask extends AskInstances {

def apply[F[_], E](implicit applicativeAsk: ApplicativeAsk[F, E]): ApplicativeAsk[F, E] =
applicativeAsk
def apply[F[_], E](implicit ask: Ask[F, E]): Ask[F, E] =
ask

def const[F[_]: Applicative, E](e: E): ApplicativeAsk[F, E] =
new ApplicativeAsk[F, E] {
def const[F[_]: Applicative, E](e: E): Ask[F, E] =
new Ask[F, E] {
val applicative: Applicative[F] = Applicative[F]
val ask: F[E] = applicative.pure(e)
}

def ask[F[_], E](implicit ask: ApplicativeAsk[F, E]): F[E] =
def ask[F[_], E](implicit ask: Ask[F, E]): F[E] =
ask.ask

def askF[F[_]]: askFPartiallyApplied[F] = new askFPartiallyApplied[F]

@inline final private[mtl] class askFPartiallyApplied[F[_]](val dummy: Boolean = false)
extends AnyVal {
@inline def apply[E]()(implicit ask: `ApplicativeAsk`[F, E]): F[E] =
@inline def apply[E]()(implicit ask: `Ask`[F, E]): F[E] =
ask.ask
}

@inline final private[mtl] class readerFEPartiallyApplied[F[_], E](val dummy: Boolean = false)
extends AnyVal {
@inline def apply[A](f: E => A)(implicit ask: ApplicativeAsk[F, E]): F[A] =
@inline def apply[A](f: E => A)(implicit ask: Ask[F, E]): F[A] =
ask.reader(f)
}

def readerFE[F[_], E]: readerFEPartiallyApplied[F, E] = new readerFEPartiallyApplied[F, E]

def reader[F[_], E, A](fun: E => A)(implicit ask: ApplicativeAsk[F, E]): F[A] =
def reader[F[_], E, A](fun: E => A)(implicit ask: Ask[F, E]): F[A] =
ask.reader(fun)

}
21 changes: 10 additions & 11 deletions core/src/main/scala/cats/mtl/ApplicativeCensor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import cats.data.{
}
import cats.implicits._

trait ApplicativeCensor[F[_], L] extends FunctorListen[F, L] {
trait ApplicativeCensor[F[_], L] extends Listen[F, L] {
val applicative: Applicative[F]
val monoid: Monoid[L]
override lazy val functor: Functor[F] = applicative
Expand All @@ -49,7 +49,7 @@ private[mtl] trait LowPriorityApplicativeCensorInstances {
M[_]: Applicative,
L0: Monoid,
L: Monoid](implicit A: ApplicativeCensor[M, L]): ApplicativeCensor[WriterT[M, L0, *], L] =
new FunctorListenInductiveWriterT[M, L0, L] with ApplicativeCensor[WriterT[M, L0, *], L] {
new ListenInductiveWriterT[M, L0, L] with ApplicativeCensor[WriterT[M, L0, *], L] {
val applicative: Applicative[WriterT[M, L0, *]] = WriterT.catsDataApplicativeForWriterT
val monoid: Monoid[L] = Monoid[L]

Expand All @@ -59,8 +59,7 @@ private[mtl] trait LowPriorityApplicativeCensorInstances {

implicit final def inductiveApplicativeCensorRWST[M[_]: Monad, R, L0: Monoid, L: Monoid, S](
implicit A: ApplicativeCensor[M, L]): ApplicativeCensor[RWST[M, R, L0, S, *], L] =
new FunctorListenInductiveRWST[M, R, L0, L, S]
with ApplicativeCensor[RWST[M, R, L0, S, *], L] {
new ListenInductiveRWST[M, R, L0, L, S] with ApplicativeCensor[RWST[M, R, L0, S, *], L] {
val applicative: Applicative[RWST[M, R, L0, S, *]] =
IndexedReaderWriterStateT.catsDataMonadForRWST
val monoid: Monoid[L] = Monoid[L]
Expand All @@ -74,7 +73,7 @@ private[mtl] trait ApplicativeCensorInstances extends LowPriorityApplicativeCens
implicit final def applicativeCensorWriterT[M[_], L](
implicit M: Applicative[M],
L: Monoid[L]): ApplicativeCensor[WriterT[M, L, *], L] =
new FunctorListenWriterT[M, L] with ApplicativeCensor[WriterT[M, L, *], L] {
new ListenWriterT[M, L] with ApplicativeCensor[WriterT[M, L, *], L] {
val applicative: Applicative[WriterT[M, L, *]] =
cats.data.WriterT.catsDataApplicativeForWriterT[M, L]

Expand All @@ -91,7 +90,7 @@ private[mtl] trait ApplicativeCensorInstances extends LowPriorityApplicativeCens
implicit final def applicativeCensorRWST[M[_], R, L, S](
implicit L: Monoid[L],
M: Monad[M]): ApplicativeCensor[RWST[M, R, L, S, *], L] =
new FunctorListenRWST[M, R, L, S] with ApplicativeCensor[RWST[M, R, L, S, *], L] {
new ListenRWST[M, R, L, S] with ApplicativeCensor[RWST[M, R, L, S, *], L] {
val applicative: Applicative[RWST[M, R, L, S, *]] =
IndexedReaderWriterStateT.catsDataMonadForRWST

Expand All @@ -109,7 +108,7 @@ private[mtl] trait ApplicativeCensorInstances extends LowPriorityApplicativeCens
implicit L: Monoid[L],
A: ApplicativeCensor[F, L],
F: Applicative[F]): ApplicativeCensor[Kleisli[F, R, *], L] =
new FunctorListenKleisli[F, R, L] with ApplicativeCensor[Kleisli[F, R, *], L] {
new ListenKleisli[F, R, L] with ApplicativeCensor[Kleisli[F, R, *], L] {
val applicative: Applicative[Kleisli[F, R, *]] = Kleisli.catsDataApplicativeForKleisli
val monoid: cats.Monoid[L] = L

Expand All @@ -121,7 +120,7 @@ private[mtl] trait ApplicativeCensorInstances extends LowPriorityApplicativeCens
implicit L: Monoid[L],
A: ApplicativeCensor[F, L],
F: Monad[F]): ApplicativeCensor[StateT[F, S, *], L] =
new FunctorListenStateT[F, S, L] with ApplicativeCensor[StateT[F, S, *], L] {
new ListenStateT[F, S, L] with ApplicativeCensor[StateT[F, S, *], L] {
val applicative: Applicative[StateT[F, S, *]] =
IndexedStateT.catsDataMonadForIndexedStateT
val monoid: cats.Monoid[L] = L
Expand All @@ -134,7 +133,7 @@ private[mtl] trait ApplicativeCensorInstances extends LowPriorityApplicativeCens
implicit L: Monoid[L],
A: ApplicativeCensor[F, L],
F: Monad[F]): ApplicativeCensor[EitherT[F, E, *], L] =
new FunctorListenEitherT[F, E, L] with ApplicativeCensor[EitherT[F, E, *], L] {
new ListenEitherT[F, E, L] with ApplicativeCensor[EitherT[F, E, *], L] {
val applicative: Applicative[EitherT[F, E, *]] = EitherT.catsDataMonadErrorForEitherT
val monoid: cats.Monoid[L] = L

Expand All @@ -147,7 +146,7 @@ private[mtl] trait ApplicativeCensorInstances extends LowPriorityApplicativeCens
A: ApplicativeCensor[F, L],
F: Monad[F],
E: Semigroup[E]): ApplicativeCensor[IorT[F, E, *], L] =
new FunctorListenIorT[F, E, L] with ApplicativeCensor[IorT[F, E, *], L] {
new ListenIorT[F, E, L] with ApplicativeCensor[IorT[F, E, *], L] {
val applicative: Applicative[IorT[F, E, *]] = IorT.catsDataMonadErrorForIorT
val monoid: cats.Monoid[L] = L

Expand All @@ -159,7 +158,7 @@ private[mtl] trait ApplicativeCensorInstances extends LowPriorityApplicativeCens
implicit L: Monoid[L],
A: ApplicativeCensor[F, L],
F: Monad[F]): ApplicativeCensor[OptionT[F, *], L] =
new FunctorListenOptionT[F, L] with ApplicativeCensor[OptionT[F, *], L] {
new ListenOptionT[F, L] with ApplicativeCensor[OptionT[F, *], L] {
val applicative: Applicative[OptionT[F, *]] = OptionT.catsDataMonadForOptionT
val monoid: cats.Monoid[L] = L

Expand Down
Loading

0 comments on commit 6aa812a

Please sign in to comment.