typelevel / cats-mtl
Showing 32 of 55 files from the diff.

@@ -10,18 +10,15 @@
Loading
10 10
  implicit def F: FunctorListen[F, L]
11 11
12 12
  // external laws:
13 -
  def listenRespectsTell(l: L): IsEq[F[(Unit, L)]] = {
13 +
  def listenRespectsTell(l: L): IsEq[F[(Unit, L)]] =
14 14
    F.listen(F.tell(l)) <-> F.tell(l).as(((), l))
15 -
  }
16 15
17 -
  def listenAddsNoEffects[A](fa: F[A]): IsEq[F[A]] = {
16 +
  def listenAddsNoEffects[A](fa: F[A]): IsEq[F[A]] =
18 17
    F.listen(fa).map(_._1) <-> fa
19 -
  }
20 18
21 19
  // internal law:
22 -
  def listensIsListenThenMap[A, B](fa: F[A], f: L => B): IsEq[F[(A, B)]] = {
20 +
  def listensIsListenThenMap[A, B](fa: F[A], f: L => B): IsEq[F[(A, B)]] =
23 21
    F.listens(fa)(f) <-> F.listen(fa).map { case (a, l) => (a, f(l)) }
24 -
  }
25 22
}
26 23
27 24
object FunctorListenLaws {

@@ -36,85 +36,112 @@
Loading
36 36
  def scope[A](e: E)(fa: F[A]): F[A] = local(_ => e)(fa)
37 37
}
38 38
39 -
private[mtl] trait LowPriorityApplicativeLocalInstances extends LowPriorityApplicativeLocalInstancesCompat {
40 -
  implicit def applicativeLocalForKleisli[F[_]: Monad, E, R](implicit F0: ApplicativeLocal[F, E]): ApplicativeLocal[Kleisli[F, R, *], E] =
41 -
    new ApplicativeLocal[Kleisli[F, R, *], E] with ApplicativeAskForMonadPartialOrder[F, Kleisli[F, R, *], E] {
39 +
private[mtl] trait LowPriorityApplicativeLocalInstances
40 +
    extends LowPriorityApplicativeLocalInstancesCompat {
41 +
  implicit def applicativeLocalForKleisli[F[_]: Monad, E, R](
42 +
      implicit F0: ApplicativeLocal[F, E]): ApplicativeLocal[Kleisli[F, R, *], E] =
43 +
    new ApplicativeLocal[Kleisli[F, R, *], E]
44 +
      with ApplicativeAskForMonadPartialOrder[F, Kleisli[F, R, *], E] {
42 45
      def local[A](f: E => E)(fa: Kleisli[F, R, A]): Kleisli[F, R, A] =
43 46
        Kleisli(r => F0.local(f)(fa.run(r)))
44 -
      val F: ApplicativeAsk[F,E] = F0
45 -
      val lift: MonadPartialOrder[F, Kleisli[F,R, *]] = MonadPartialOrder.monadPartialOrderForKleisli[F, R]
47 +
      val F: ApplicativeAsk[F, E] = F0
48 +
      val lift: MonadPartialOrder[F, Kleisli[F, R, *]] =
49 +
        MonadPartialOrder.monadPartialOrderForKleisli[F, R]
46 50
    }
47 51
}
48 52
49 53
private[mtl] trait ApplicativeLocalInstances extends LowPriorityApplicativeLocalInstances {
50 54
51 -
  implicit def baseApplicativeLocalForKleisli[F[_], E](implicit F: Applicative[F]): ApplicativeLocal[Kleisli[F, E, *], E] =
55 +
  implicit def baseApplicativeLocalForKleisli[F[_], E](
56 +
      implicit F: Applicative[F]): ApplicativeLocal[Kleisli[F, E, *], E] =
52 57
    new ApplicativeLocal[Kleisli[F, E, *], E] {
53 58
      def local[A](f: E => E)(fa: Kleisli[F, E, A]) = fa.local(f)
54 59
      val applicative = Applicative[Kleisli[F, E, *]]
55 60
      def ask = Kleisli.ask[F, E]
56 61
    }
57 62
58 -
  implicit def baseApplicativeLocalForRWST[F[_], E, L, S](implicit F: Monad[F], L: Monoid[L]): ApplicativeLocal[RWST[F, E, L, S, *], E] =
63 +
  implicit def baseApplicativeLocalForRWST[F[_], E, L, S](
64 +
      implicit F: Monad[F],
65 +
      L: Monoid[L]): ApplicativeLocal[RWST[F, E, L, S, *], E] =
59 66
    new ApplicativeLocal[RWST[F, E, L, S, *], E] {
60 67
      def local[A](f: E => E)(fa: RWST[F, E, L, S, A]) = fa.local(f)
61 68
      val applicative = Applicative[RWST[F, E, L, S, *]]
62 69
      def ask = RWST.ask[F, E, L, S]
63 70
    }
64 71
65 -
  implicit def applicativeLocalForWriterT[F[_]: Monad, E, L: Monoid](implicit F0: ApplicativeLocal[F, E]): ApplicativeLocal[WriterT[F, L, *], E] =
66 -
    new ApplicativeLocal[WriterT[F, L, *], E] with ApplicativeAskForMonadPartialOrder[F, WriterT[F, L, *], E] {
72 +
  implicit def applicativeLocalForWriterT[F[_]: Monad, E, L: Monoid](
73 +
      implicit F0: ApplicativeLocal[F, E]): ApplicativeLocal[WriterT[F, L, *], E] =
74 +
    new ApplicativeLocal[WriterT[F, L, *], E]
75 +
      with ApplicativeAskForMonadPartialOrder[F, WriterT[F, L, *], E] {
67 76
      def local[A](f: E => E)(fa: WriterT[F, L, A]): WriterT[F, L, A] =
68 77
        WriterT(F0.local(f)(fa.run))
69 -
      val F: ApplicativeAsk[F,E] = F0
70 -
      val lift: MonadPartialOrder[F, WriterT[F,L, *]] = MonadPartialOrder.monadPartialOrderForWriterT[F, L]
78 +
      val F: ApplicativeAsk[F, E] = F0
79 +
      val lift: MonadPartialOrder[F, WriterT[F, L, *]] =
80 +
        MonadPartialOrder.monadPartialOrderForWriterT[F, L]
71 81
    }
72 82
73 -
  implicit def applicativeLocalForRWST[F[_]: Monad, E, R, L: Monoid, S](implicit F0: ApplicativeLocal[F, E]): ApplicativeLocal[RWST[F, R, L, S, *], E] =
74 -
    new ApplicativeLocal[RWST[F, R, L, S, *], E] with ApplicativeAskForMonadPartialOrder[F, RWST[F, R, L, S, *], E] {
83 +
  implicit def applicativeLocalForRWST[F[_]: Monad, E, R, L: Monoid, S](
84 +
      implicit F0: ApplicativeLocal[F, E]): ApplicativeLocal[RWST[F, R, L, S, *], E] =
85 +
    new ApplicativeLocal[RWST[F, R, L, S, *], E]
86 +
      with ApplicativeAskForMonadPartialOrder[F, RWST[F, R, L, S, *], E] {
75 87
      def local[A](f: E => E)(fa: RWST[F, R, L, S, A]): RWST[F, R, L, S, A] =
76 88
        RWST((r, s) => F0.local(f)(fa.run(r, s)))
77 -
      val F: ApplicativeAsk[F,E] = F0
78 -
      val lift: MonadPartialOrder[F, RWST[F,R, L, S, *]] = MonadPartialOrder.monadPartialOrderForRWST[F, R, L, S]
89 +
      val F: ApplicativeAsk[F, E] = F0
90 +
      val lift: MonadPartialOrder[F, RWST[F, R, L, S, *]] =
91 +
        MonadPartialOrder.monadPartialOrderForRWST[F, R, L, S]
79 92
    }
80 93
81 -
  implicit def applicativeLocalForStateT[F[_]: Monad, E, S](implicit F0: ApplicativeLocal[F, E]): ApplicativeLocal[StateT[F, S, *], E] =
82 -
    new ApplicativeLocal[StateT[F, S, *], E] with ApplicativeAskForMonadPartialOrder[F, StateT[F, S, *], E] {
94 +
  implicit def applicativeLocalForStateT[F[_]: Monad, E, S](
95 +
      implicit F0: ApplicativeLocal[F, E]): ApplicativeLocal[StateT[F, S, *], E] =
96 +
    new ApplicativeLocal[StateT[F, S, *], E]
97 +
      with ApplicativeAskForMonadPartialOrder[F, StateT[F, S, *], E] {
83 98
      def local[A](f: E => E)(fa: StateT[F, S, A]): StateT[F, S, A] =
84 99
        StateT(s => F0.local(f)(fa.run(s)))
85 -
      val F: ApplicativeAsk[F,E] = F0
86 -
      val lift: MonadPartialOrder[F, StateT[F,S, *]] = MonadPartialOrder.monadPartialOrderForStateT[F, S]
100 +
      val F: ApplicativeAsk[F, E] = F0
101 +
      val lift: MonadPartialOrder[F, StateT[F, S, *]] =
102 +
        MonadPartialOrder.monadPartialOrderForStateT[F, S]
87 103
    }
88 104
89 -
  implicit def applicativeLocalForEitherT[F[_]: Monad, E, E2](implicit F0: ApplicativeLocal[F, E]): ApplicativeLocal[EitherT[F, E2, *], E] =
90 -
    new ApplicativeLocal[EitherT[F, E2, *], E] with ApplicativeAskForMonadPartialOrder[F, EitherT[F, E2, *], E] {
105 +
  implicit def applicativeLocalForEitherT[F[_]: Monad, E, E2](
106 +
      implicit F0: ApplicativeLocal[F, E]): ApplicativeLocal[EitherT[F, E2, *], E] =
107 +
    new ApplicativeLocal[EitherT[F, E2, *], E]
108 +
      with ApplicativeAskForMonadPartialOrder[F, EitherT[F, E2, *], E] {
91 109
      def local[A](f: E => E)(fa: EitherT[F, E2, A]): EitherT[F, E2, A] =
92 110
        EitherT(F0.local(f)(fa.value))
93 -
      val F: ApplicativeAsk[F,E] = F0
94 -
      val lift: MonadPartialOrder[F, EitherT[F,E2, *]] = MonadPartialOrder.monadPartialOrderForEitherT[F, E2]
111 +
      val F: ApplicativeAsk[F, E] = F0
112 +
      val lift: MonadPartialOrder[F, EitherT[F, E2, *]] =
113 +
        MonadPartialOrder.monadPartialOrderForEitherT[F, E2]
95 114
    }
96 115
97 -
  implicit def applicativeLocalForOptionT[F[_]: Monad, E](implicit F0: ApplicativeLocal[F, E]): ApplicativeLocal[OptionT[F, *], E] =
98 -
    new ApplicativeLocal[OptionT[F, *], E] with ApplicativeAskForMonadPartialOrder[F, OptionT[F, *], E] {
116 +
  implicit def applicativeLocalForOptionT[F[_]: Monad, E](
117 +
      implicit F0: ApplicativeLocal[F, E]): ApplicativeLocal[OptionT[F, *], E] =
118 +
    new ApplicativeLocal[OptionT[F, *], E]
119 +
      with ApplicativeAskForMonadPartialOrder[F, OptionT[F, *], E] {
99 120
      def local[A](f: E => E)(fa: OptionT[F, A]): OptionT[F, A] =
100 121
        OptionT(F0.local(f)(fa.value))
101 -
      val F: ApplicativeAsk[F,E] = F0
102 -
      val lift: MonadPartialOrder[F, OptionT[F, *]] = MonadPartialOrder.monadPartialOrderForOptionT[F]
122 +
      val F: ApplicativeAsk[F, E] = F0
123 +
      val lift: MonadPartialOrder[F, OptionT[F, *]] =
124 +
        MonadPartialOrder.monadPartialOrderForOptionT[F]
103 125
    }
104 126
105 -
  implicit def applicativeLocalForIorT[F[_]: Monad, E, E2: Semigroup](implicit F0: ApplicativeLocal[F, E]): ApplicativeLocal[IorT[F, E2, *], E] =
106 -
    new ApplicativeLocal[IorT[F, E2, *], E] with ApplicativeAskForMonadPartialOrder[F, IorT[F, E2, *], E] {
127 +
  implicit def applicativeLocalForIorT[F[_]: Monad, E, E2: Semigroup](
128 +
      implicit F0: ApplicativeLocal[F, E]): ApplicativeLocal[IorT[F, E2, *], E] =
129 +
    new ApplicativeLocal[IorT[F, E2, *], E]
130 +
      with ApplicativeAskForMonadPartialOrder[F, IorT[F, E2, *], E] {
107 131
      def local[A](f: E => E)(fa: IorT[F, E2, A]): IorT[F, E2, A] =
108 132
        IorT(F0.local(f)(fa.value))
109 -
      val F: ApplicativeAsk[F,E] = F0
110 -
      val lift: MonadPartialOrder[F, IorT[F,E2, *]] = MonadPartialOrder.monadPartialOrderForIorT[F, E2]
133 +
      val F: ApplicativeAsk[F, E] = F0
134 +
      val lift: MonadPartialOrder[F, IorT[F, E2, *]] =
135 +
        MonadPartialOrder.monadPartialOrderForIorT[F, E2]
111 136
    }
112 137
}
113 138
114 139
object ApplicativeLocal extends ApplicativeLocalInstances {
115 140
  def apply[F[_], A](implicit local: ApplicativeLocal[F, A]): ApplicativeLocal[F, A] = local
116 141
117 -
  def local[F[_], E, A](f: E => E)(fa: F[A])(implicit local: ApplicativeLocal[F, E]): F[A] = local.local(f)(fa)
142 +
  def local[F[_], E, A](f: E => E)(fa: F[A])(implicit local: ApplicativeLocal[F, E]): F[A] =
143 +
    local.local(f)(fa)
118 144
119 -
  def scope[F[_], E, A](e: E)(fa: F[A])(implicit local: ApplicativeLocal[F, E]): F[A] = local.scope(e)(fa)
145 +
  def scope[F[_], E, A](e: E)(fa: F[A])(implicit local: ApplicativeLocal[F, E]): F[A] =
146 +
    local.scope(e)(fa)
120 147
}

@@ -11,13 +11,11 @@
Loading
11 11
  implicit def functor(implicit F: FunctorTell[F, L]): Functor[F] = F.functor
12 12
13 13
  // internal laws:
14 -
  def writerIsTellAndMap[A](a: A, l: L): IsEq[F[A]] = {
14 +
  def writerIsTellAndMap[A](a: A, l: L): IsEq[F[A]] =
15 15
    F.tell(l).as(a) <-> F.writer(a, l)
16 -
  }
17 16
18 -
  def tupleIsWriterFlipped[A](a: A, l: L): IsEq[F[A]] = {
17 +
  def tupleIsWriterFlipped[A](a: A, l: L): IsEq[F[A]] =
19 18
    F.writer(a, l) <-> F.tuple((l, a))
20 -
  }
21 19
22 20
}
23 21

@@ -11,13 +11,12 @@
Loading
11 11
trait FunctorTellTests[F[_], L] extends Laws {
12 12
  def laws: FunctorTellLaws[F, L]
13 13
14 -
  def functorTell[A: Arbitrary](implicit
15 -
                                    ArbFA: Arbitrary[F[A]],
16 -
                                    ArbL: Arbitrary[L],
17 -
                                    CogenA: Cogen[A],
18 -
                                    EqFU: Eq[F[Unit]],
19 -
                                    EqFA: Eq[F[A]]
20 -
                                   ): RuleSet = {
14 +
  def functorTell[A: Arbitrary](
15 +
      implicit ArbFA: Arbitrary[F[A]],
16 +
      ArbL: Arbitrary[L],
17 +
      CogenA: Cogen[A],
18 +
      EqFU: Eq[F[Unit]],
19 +
      EqFA: Eq[F[A]]): RuleSet = {
21 20
    new DefaultRuleSet(
22 21
      name = "functorTell",
23 22
      parent = None,

@@ -48,9 +48,8 @@
Loading
48 48
  def raise[A](e: E): F[A]
49 49
50 50
  def catchNonFatal[A](a: => A)(f: Throwable => E)(implicit A: Applicative[F]): F[A] = {
51 -
    try {
52 -
      A.pure(a)
53 -
    } catch {
51 +
    try A.pure(a)
52 +
    catch {
54 53
      case NonFatal(ex) => raise(f(ex))
55 54
    }
56 55
  }
@@ -61,56 +60,63 @@
Loading
61 60
62 61
private[mtl] trait FunctorRaiseMonadPartialOrder[F[_], G[_], E] extends FunctorRaise[G, E] {
63 62
  val lift: MonadPartialOrder[F, G]
64 -
  val F: FunctorRaise[F,E]
65 -
  
63 +
  val F: FunctorRaise[F, E]
64 +
66 65
  override def functor = lift.monadG
67 66
  override def raise[A](e: E) = lift(F.raise(e))
68 67
}
69 68
70 69
private[mtl] trait LowPriorityFunctorRaiseInstances {
71 70
  implicit def functorRaiseForMonadPartialOrder[F[_], G[_]: Functor, E](
72 -
    implicit F: FunctorRaise[F, E], 
73 -
    lift: MonadPartialOrder[F, G]
71 +
      implicit F: FunctorRaise[F, E],
72 +
      lift: MonadPartialOrder[F, G]
74 73
  ): FunctorRaise[G, E] =
75 -
      new FunctorRaise[G, E] {
76 -
        val functor = Functor[G]
77 -
        def raise[A](e: E) = lift(F.raise(e))
78 -
      }
74 +
    new FunctorRaise[G, E] {
75 +
      val functor = Functor[G]
76 +
      def raise[A](e: E) = lift(F.raise(e))
77 +
    }
79 78
}
80 79
81 80
private[mtl] trait FunctorRaiseInstances extends LowPriorityFunctorRaiseInstances {
82 -
  implicit final def raiseEitherT[M[_], E](implicit M: Monad[M]): FunctorRaise[EitherTC[M, E]#l, E] =
81 +
  implicit final def raiseEitherT[M[_], E](
82 +
      implicit M: Monad[M]): FunctorRaise[EitherTC[M, E]#l, E] =
83 83
    ApplicativeHandle.handleEitherT
84 84
85 85
  implicit final def raiseEither[E]: FunctorRaise[EitherC[E]#l, E] =
86 86
    ApplicativeHandle.handleEither
87 87
88 -
  implicit final def raiseOptionT[M[_]](implicit M: Monad[M]): FunctorRaise[OptionTC[M]#l, Unit] =
88 +
  implicit final def raiseOptionT[M[_]](
89 +
      implicit M: Monad[M]): FunctorRaise[OptionTC[M]#l, Unit] =
89 90
    ApplicativeHandle.handleOptionT
90 91
91 -
  implicit final def raiseOption[E]: FunctorRaise[Option, Unit] = 
92 +
  implicit final def raiseOption[E]: FunctorRaise[Option, Unit] =
92 93
    ApplicativeHandle.handleOption
93 94
94 -
  implicit final def raiseValidated[E](implicit E: Semigroup[E]): FunctorRaise[Validated[E, ?], E] =
95 +
  implicit final def raiseValidated[E](
96 +
      implicit E: Semigroup[E]): FunctorRaise[Validated[E, ?], E] =
95 97
    ApplicativeHandle.handleValidated
96 98
97 99
  implicit final def raiseIor[E](implicit E: Semigroup[E]): FunctorRaise[Ior[E, *], E] =
98 100
    ApplicativeHandle.handleIor[E]
99 -
  
100 -
  implicit final def raiseIorT[F[_], E](implicit E: Semigroup[E], F: Monad[F]): FunctorRaise[IorT[F, E, *], E] =
101 +
102 +
  implicit final def raiseIorT[F[_], E](
103 +
      implicit E: Semigroup[E],
104 +
      F: Monad[F]): FunctorRaise[IorT[F, E, *], E] =
101 105
    ApplicativeHandle.handleIorT[F, E]
102 -
    
106 +
103 107
}
104 108
105 109
object FunctorRaise extends FunctorRaiseInstances {
106 -
  def apply[F[_], E](implicit functorRaise: FunctorRaise[F, E]): FunctorRaise[F, E] = functorRaise
110 +
  def apply[F[_], E](implicit functorRaise: FunctorRaise[F, E]): FunctorRaise[F, E] =
111 +
    functorRaise
107 112
108 113
  def raise[F[_], E, A](e: E)(implicit raise: FunctorRaise[F, _ >: E]): F[A] =
109 114
    raise.raise(e)
110 115
111 116
  def raiseF[F[_]]: raiseFPartiallyApplied[F] = new raiseFPartiallyApplied[F]()
112 117
113 -
  final private[mtl] class raiseFPartiallyApplied[F[_]](val dummy: Boolean = false) extends AnyVal {
118 +
  final private[mtl] class raiseFPartiallyApplied[F[_]](val dummy: Boolean = false)
119 +
      extends AnyVal {
114 120
    @inline def apply[E, A](e: E)(implicit raise: FunctorRaise[F, _ >: E]): F[A] =
115 121
      raise.raise(e)
116 122
  }

@@ -16,41 +16,46 @@
Loading
16 16
17 17
  def materialize[A](fa: F[A]): F[E Ior A]
18 18
19 -
  def memento[A](fa: F[A]): F[Either[E, A]] = monad.flatMap(materialize(fa)) {
20 -
    case Ior.Left(e)    => monad.pure(Left(e))
21 -
    case Ior.Right(a)   => monad.pure(Right(a))
22 -
    case Ior.Both(e, a) => monad.as(dictate(e), Right(a))
23 -
  }
24 -
25 -
  def absolve[A](fa: F[A])(a: => A): F[A] = monad.map(materialize(fa)) {
26 -
    case Ior.Left(_)     => a
27 -
    case Ior.Right(a0)   => a0
28 -
    case Ior.Both(_, a0) => a0
29 -
  }
30 -
31 -
  def condemn[A](fa: F[A]): F[A] = monad.flatMap(materialize(fa)) {
32 -
    case Ior.Left(e)    => confess(e)
33 -
    case Ior.Right(a)   => monad.pure(a)
34 -
    case Ior.Both(e, _) => confess(e)
35 -
  }
36 -
37 -
  def retcon[A](fa: F[A])(cc: E => E): F[A] = monad.flatMap(materialize(fa)) {
38 -
    case Ior.Left(e)    => confess(cc(e))
39 -
    case Ior.Right(a)   => monad.pure(a)
40 -
    case Ior.Both(e, a) => monad.as(dictate(cc(e)), a)
41 -
  }
42 -
43 -
  def chronicle[A](ior: E Ior A): F[A] = ior match {
44 -
    case Ior.Left(e)    => confess(e)
45 -
    case Ior.Right(a)   => monad.pure(a)
46 -
    case Ior.Both(e, a) => monad.as(dictate(e), a)
47 -
  }
48 -
}
19 +
  def memento[A](fa: F[A]): F[Either[E, A]] =
20 +
    monad.flatMap(materialize(fa)) {
21 +
      case Ior.Left(e) => monad.pure(Left(e))
22 +
      case Ior.Right(a) => monad.pure(Right(a))
23 +
      case Ior.Both(e, a) => monad.as(dictate(e), Right(a))
24 +
    }
25 +
26 +
  def absolve[A](fa: F[A])(a: => A): F[A] =
27 +
    monad.map(materialize(fa)) {
28 +
      case Ior.Left(_) => a
29 +
      case Ior.Right(a0) => a0
30 +
      case Ior.Both(_, a0) => a0
31 +
    }
49 32
33 +
  def condemn[A](fa: F[A]): F[A] =
34 +
    monad.flatMap(materialize(fa)) {
35 +
      case Ior.Left(e) => confess(e)
36 +
      case Ior.Right(a) => monad.pure(a)
37 +
      case Ior.Both(e, _) => confess(e)
38 +
    }
39 +
40 +
  def retcon[A](fa: F[A])(cc: E => E): F[A] =
41 +
    monad.flatMap(materialize(fa)) {
42 +
      case Ior.Left(e) => confess(cc(e))
43 +
      case Ior.Right(a) => monad.pure(a)
44 +
      case Ior.Both(e, a) => monad.as(dictate(cc(e)), a)
45 +
    }
46 +
47 +
  def chronicle[A](ior: E Ior A): F[A] =
48 +
    ior match {
49 +
      case Ior.Left(e) => confess(e)
50 +
      case Ior.Right(a) => monad.pure(a)
51 +
      case Ior.Both(e, a) => monad.as(dictate(e), a)
52 +
    }
53 +
}
50 54
51 55
private[mtl] trait MonadChronicleInstances {
52 56
53 -
  implicit def monadChronicleForIorT[F[_], E: Semigroup](implicit F: Monad[F]): MonadChronicle[IorT[F, E, *], E] =
57 +
  implicit def monadChronicleForIorT[F[_], E: Semigroup](
58 +
      implicit F: Monad[F]): MonadChronicle[IorT[F, E, *], E] =
54 59
    new MonadChronicle[IorT[F, E, *], E] {
55 60
      override val monad: Monad[IorT[F, E, *]] = IorT.catsDataMonadErrorForIorT
56 61
@@ -58,13 +63,14 @@
Loading
58 63
59 64
      override def confess[A](c: E): IorT[F, E, A] = IorT.leftT[F, A](c)
60 65
61 -
      override def materialize[A](fa: IorT[F, E, A]): IorT[F, E, E Ior A] = IorT[F, E, E Ior A] {
62 -
        F.map(fa.value) {
63 -
          case Ior.Left(e)    => Ior.right(Ior.left(e))
64 -
          case Ior.Right(a)   => Ior.right(Ior.right(a))
65 -
          case Ior.Both(e, a) => Ior.right(Ior.both(e, a))
66 +
      override def materialize[A](fa: IorT[F, E, A]): IorT[F, E, E Ior A] =
67 +
        IorT[F, E, E Ior A] {
68 +
          F.map(fa.value) {
69 +
            case Ior.Left(e) => Ior.right(Ior.left(e))
70 +
            case Ior.Right(a) => Ior.right(Ior.right(a))
71 +
            case Ior.Both(e, a) => Ior.right(Ior.both(e, a))
72 +
          }
66 73
        }
67 -
      }
68 74
    }
69 75
70 76
  implicit final def chronicleIor[E](implicit S: Semigroup[E]): MonadChronicle[Ior[E, *], E] =
@@ -75,73 +81,82 @@
Loading
75 81
76 82
      override def confess[A](c: E): Ior[E, A] = Ior.left(c)
77 83
78 -
      override def materialize[A](fa: Ior[E, A]): Ior[E, Ior[E, A]] = fa match {
79 -
        case Ior.Left(e)    => Ior.right(Ior.left(e))
80 -
        case Ior.Right(a)   => Ior.right(Ior.right(a))
81 -
        case Ior.Both(e, a) => Ior.right(Ior.both(e, a))
82 -
      }
84 +
      override def materialize[A](fa: Ior[E, A]): Ior[E, Ior[E, A]] =
85 +
        fa match {
86 +
          case Ior.Left(e) => Ior.right(Ior.left(e))
87 +
          case Ior.Right(a) => Ior.right(Ior.right(a))
88 +
          case Ior.Both(e, a) => Ior.right(Ior.both(e, a))
89 +
        }
83 90
    }
84 91
85 -
  implicit def monadChronicleForWriterT[F[_]: Monad, E, L: Monoid](implicit F: MonadChronicle[F, E]): MonadChronicle[WriterT[F, L, *], E] =
92 +
  implicit def monadChronicleForWriterT[F[_]: Monad, E, L: Monoid](
93 +
      implicit F: MonadChronicle[F, E]): MonadChronicle[WriterT[F, L, *], E] =
86 94
    new MonadChronicle[WriterT[F, L, *], E] {
87 -
      val monad: Monad[WriterT[F,L, *]] = WriterT.catsDataMonadForWriterT[F, L]
88 -
      def confess[A](c: E): WriterT[F,L,A] = WriterT.liftF(F.confess[A](c))
89 -
      def dictate(c: E): WriterT[F,L,Unit] = WriterT.liftF(F.dictate(c))
90 -
      def materialize[A](fa: WriterT[F,L,A]): WriterT[F,L,Ior[E,A]] = 
95 +
      val monad: Monad[WriterT[F, L, *]] = WriterT.catsDataMonadForWriterT[F, L]
96 +
      def confess[A](c: E): WriterT[F, L, A] = WriterT.liftF(F.confess[A](c))
97 +
      def dictate(c: E): WriterT[F, L, Unit] = WriterT.liftF(F.dictate(c))
98 +
      def materialize[A](fa: WriterT[F, L, A]): WriterT[F, L, Ior[E, A]] =
91 99
        WriterT(F.materialize(fa.run).map(_.sequence))
92 100
    }
93 101
94 -
  implicit def monadChronicleForEitherT[F[_]: Monad, E, E2](implicit F: MonadChronicle[F, E]): MonadChronicle[EitherT[F, E2, *], E] =
102 +
  implicit def monadChronicleForEitherT[F[_]: Monad, E, E2](
103 +
      implicit F: MonadChronicle[F, E]): MonadChronicle[EitherT[F, E2, *], E] =
95 104
    new MonadChronicle[EitherT[F, E2, *], E] {
96 -
      val monad: Monad[EitherT[F,E2, *]] = EitherT.catsDataMonadErrorForEitherT[F, E2]
97 -
      def confess[A](c: E): EitherT[F,E2,A] = EitherT.liftF(F.confess[A](c))
98 -
      def dictate(c: E): EitherT[F,E2,Unit] = EitherT.liftF(F.dictate(c))
99 -
      def materialize[A](fa: EitherT[F,E2,A]): EitherT[F,E2,Ior[E,A]] = 
105 +
      val monad: Monad[EitherT[F, E2, *]] = EitherT.catsDataMonadErrorForEitherT[F, E2]
106 +
      def confess[A](c: E): EitherT[F, E2, A] = EitherT.liftF(F.confess[A](c))
107 +
      def dictate(c: E): EitherT[F, E2, Unit] = EitherT.liftF(F.dictate(c))
108 +
      def materialize[A](fa: EitherT[F, E2, A]): EitherT[F, E2, Ior[E, A]] =
100 109
        EitherT(F.materialize(fa.value).map(_.sequence))
101 110
    }
102 111
103 -
  implicit def monadChronicleForKleisli[F[_]: Monad, E, R](implicit F: MonadChronicle[F, E]): MonadChronicle[Kleisli[F, R, *], E] =
112 +
  implicit def monadChronicleForKleisli[F[_]: Monad, E, R](
113 +
      implicit F: MonadChronicle[F, E]): MonadChronicle[Kleisli[F, R, *], E] =
104 114
    new MonadChronicle[Kleisli[F, R, *], E] {
105 -
      val monad: Monad[Kleisli[F,R, *]] = Kleisli.catsDataMonadForKleisli[F, R]
106 -
      def confess[A](c: E): Kleisli[F,R,A] = Kleisli.liftF(F.confess[A](c))
107 -
      def dictate(c: E): Kleisli[F,R,Unit] = Kleisli.liftF(F.dictate(c))
108 -
      def materialize[A](fa: Kleisli[F,R,A]): Kleisli[F,R,Ior[E,A]] = 
115 +
      val monad: Monad[Kleisli[F, R, *]] = Kleisli.catsDataMonadForKleisli[F, R]
116 +
      def confess[A](c: E): Kleisli[F, R, A] = Kleisli.liftF(F.confess[A](c))
117 +
      def dictate(c: E): Kleisli[F, R, Unit] = Kleisli.liftF(F.dictate(c))
118 +
      def materialize[A](fa: Kleisli[F, R, A]): Kleisli[F, R, Ior[E, A]] =
109 119
        Kleisli(r => F.materialize(fa.run(r)))
110 120
    }
111 121
112 -
  implicit def monadChronicleForStateT[F[_]: Monad, E, S](implicit F: MonadChronicle[F, E]): MonadChronicle[StateT[F, S, *], E] =
122 +
  implicit def monadChronicleForStateT[F[_]: Monad, E, S](
123 +
      implicit F: MonadChronicle[F, E]): MonadChronicle[StateT[F, S, *], E] =
113 124
    new MonadChronicle[StateT[F, S, *], E] {
114 -
      val monad: Monad[StateT[F,S, *]] = IndexedStateT.catsDataMonadForIndexedStateT[F, S]
115 -
      def confess[A](c: E): StateT[F,S,A] = StateT.liftF(F.confess[A](c))
116 -
      def dictate(c: E): StateT[F,S,Unit] = StateT.liftF(F.dictate(c))
117 -
      def materialize[A](fa: StateT[F,S,A]): StateT[F,S,Ior[E,A]] = 
118 -
        StateT(s => F.materialize(fa.run(s)).map {
119 -
          case Both(e, (s2, a)) => (s2, Both(e, a))
120 -
          case Ior.Left(e) => (s, Ior.Left(e))
121 -
          case Ior.Right((s2, a)) => (s2, Ior.Right(a))
122 -
        })
125 +
      val monad: Monad[StateT[F, S, *]] = IndexedStateT.catsDataMonadForIndexedStateT[F, S]
126 +
      def confess[A](c: E): StateT[F, S, A] = StateT.liftF(F.confess[A](c))
127 +
      def dictate(c: E): StateT[F, S, Unit] = StateT.liftF(F.dictate(c))
128 +
      def materialize[A](fa: StateT[F, S, A]): StateT[F, S, Ior[E, A]] =
129 +
        StateT(s =>
130 +
          F.materialize(fa.run(s)).map {
131 +
            case Both(e, (s2, a)) => (s2, Both(e, a))
132 +
            case Ior.Left(e) => (s, Ior.Left(e))
133 +
            case Ior.Right((s2, a)) => (s2, Ior.Right(a))
134 +
          })
123 135
    }
124 136
125 -
  implicit def monadChronicleForOptionT[F[_]: Monad, E](implicit F: MonadChronicle[F, E]): MonadChronicle[OptionT[F, *], E] =
137 +
  implicit def monadChronicleForOptionT[F[_]: Monad, E](
138 +
      implicit F: MonadChronicle[F, E]): MonadChronicle[OptionT[F, *], E] =
126 139
    new MonadChronicle[OptionT[F, *], E] {
127 -
      val monad: Monad[OptionT[F,*]] = OptionT.catsDataMonadForOptionT[F]
128 -
      def confess[A](c: E): OptionT[F,A] = OptionT.liftF(F.confess[A](c))
129 -
      def dictate(c: E): OptionT[F,Unit] = OptionT.liftF(F.dictate(c))
130 -
      def materialize[A](fa: OptionT[F,A]): OptionT[F,Ior[E,A]] = 
140 +
      val monad: Monad[OptionT[F, *]] = OptionT.catsDataMonadForOptionT[F]
141 +
      def confess[A](c: E): OptionT[F, A] = OptionT.liftF(F.confess[A](c))
142 +
      def dictate(c: E): OptionT[F, Unit] = OptionT.liftF(F.dictate(c))
143 +
      def materialize[A](fa: OptionT[F, A]): OptionT[F, Ior[E, A]] =
131 144
        OptionT(F.materialize(fa.value).map(_.sequence))
132 145
    }
133 146
134 -
  implicit def monadChronicleForRWST[F[_]: Monad, E, R, L: Monoid, S](implicit F: MonadChronicle[F, E]): MonadChronicle[RWST[F, R, L, S, *], E] =
147 +
  implicit def monadChronicleForRWST[F[_]: Monad, E, R, L: Monoid, S](
148 +
      implicit F: MonadChronicle[F, E]): MonadChronicle[RWST[F, R, L, S, *], E] =
135 149
    new MonadChronicle[RWST[F, R, L, S, *], E] {
136 150
      val monad: Monad[RWST[F, R, L, S, *]] = IndexedRWST.catsDataMonadForRWST[F, R, L, S]
137 -
      def confess[A](c: E): RWST[F, R, L, S,A] = RWST.liftF(F.confess[A](c))
138 -
      def dictate(c: E): RWST[F, R, L, S,Unit] = RWST.liftF(F.dictate(c))
139 -
      def materialize[A](fa: RWST[F, R, L, S,A]): RWST[F, R, L, S,Ior[E,A]] = 
140 -
        RWST((r, s) => F.materialize(fa.run(r, s)).map {
141 -
          case Both(e, (l, s2, a)) => (l, s2, Both(e, a))
142 -
          case Ior.Left(e) => (Monoid[L].empty, s, Ior.Left(e))
143 -
          case Ior.Right((l, s2, a)) => (l, s2, Ior.Right(a))
144 -
        })
151 +
      def confess[A](c: E): RWST[F, R, L, S, A] = RWST.liftF(F.confess[A](c))
152 +
      def dictate(c: E): RWST[F, R, L, S, Unit] = RWST.liftF(F.dictate(c))
153 +
      def materialize[A](fa: RWST[F, R, L, S, A]): RWST[F, R, L, S, Ior[E, A]] =
154 +
        RWST((r, s) =>
155 +
          F.materialize(fa.run(r, s)).map {
156 +
            case Both(e, (l, s2, a)) => (l, s2, Both(e, a))
157 +
            case Ior.Left(e) => (Monoid[L].empty, s, Ior.Left(e))
158 +
            case Ior.Right((l, s2, a)) => (l, s2, Ior.Right(a))
159 +
          })
145 160
    }
146 161
}
147 162

@@ -7,9 +7,10 @@
Loading
7 7
}
8 8
9 9
final class LocalOps[F[_], A](val fa: F[A]) extends AnyVal {
10 -
  def local[E](f: E => E)(implicit applicativeLocal: ApplicativeLocal[F, E]): F[A] = applicativeLocal.local(f)(fa)
11 -
  def scope[E](e: E)(implicit applicativeLocal: ApplicativeLocal[F, E]): F[A] = applicativeLocal.scope(e)(fa)
10 +
  def local[E](f: E => E)(implicit applicativeLocal: ApplicativeLocal[F, E]): F[A] =
11 +
    applicativeLocal.local(f)(fa)
12 +
  def scope[E](e: E)(implicit applicativeLocal: ApplicativeLocal[F, E]): F[A] =
13 +
    applicativeLocal.scope(e)(fa)
12 14
}
13 15
14 16
object local extends LocalSyntax
15 -

@@ -12,22 +12,22 @@
Loading
12 12
13 13
  override def laws: ApplicativeHandleLaws[F, E] = ApplicativeHandleLaws[F, E]
14 14
15 -
  def applicativeHandle[A: Arbitrary](implicit
16 -
                                        ArbFA: Arbitrary[F[A]],
17 -
                                        ArbEE: Arbitrary[E => E],
18 -
                                        ArbE: Arbitrary[E],
19 -
                                        CogenA: Cogen[A],
20 -
                                        CogenE: Cogen[E],
21 -
                                        EqFU: Eq[F[E]],
22 -
                                        EqFA: Eq[F[A]],
23 -
                                        EqFUnit: Eq[F[Unit]],
24 -
                                        EqEitherA: Eq[F[Either[E, A]]],
25 -
                                        EqEitherUnit: Eq[F[Either[E, Unit]]]
26 -
                                       ): RuleSet = {
15 +
  def applicativeHandle[A: Arbitrary](
16 +
      implicit ArbFA: Arbitrary[F[A]],
17 +
      ArbEE: Arbitrary[E => E],
18 +
      ArbE: Arbitrary[E],
19 +
      CogenA: Cogen[A],
20 +
      CogenE: Cogen[E],
21 +
      EqFU: Eq[F[E]],
22 +
      EqFA: Eq[F[A]],
23 +
      EqFUnit: Eq[F[Unit]],
24 +
      EqEitherA: Eq[F[Either[E, A]]],
25 +
      EqEitherUnit: Eq[F[Either[E, Unit]]]): RuleSet = {
27 26
    new DefaultRuleSet(
28 27
      name = "applicativeHandle",
29 28
      parent = Some(functorRaise[A]),
30 -
      "raise and handleWith is function application" -> ∀(laws.raiseAndHandleWithIsFunctionApplication[A]  _),
29 +
      "raise and handleWith is function application" -> ∀(
30 +
        laws.raiseAndHandleWithIsFunctionApplication[A] _),
31 31
      "raise and handle is pure and function application" -> ∀(laws.raiseAndHandleIsPure[A] _),
32 32
      "pure and handleWith is pure" -> ∀(laws.handleWithPureIsPure[A] _),
33 33
      "pure and handle is pure" -> ∀(laws.handlePureIsPure[A] _),
@@ -40,7 +40,8 @@
Loading
40 40
}
41 41
42 42
object ApplicativeHandleTests {
43 -
  def apply[F[_], E](implicit instance0: ApplicativeHandle[F, E]): ApplicativeHandleTests[F, E] = {
43 +
  def apply[F[_], E](
44 +
      implicit instance0: ApplicativeHandle[F, E]): ApplicativeHandleTests[F, E] = {
44 45
    new ApplicativeHandleTests[F, E] {
45 46
      override lazy val handleInstance: ApplicativeHandle[F, E] = instance0
46 47
      override lazy val raiseInstance: FunctorRaise[F, E] = instance0

@@ -13,14 +13,13 @@
Loading
13 13
14 14
  def laws: ApplicativeAskLaws[F, E] = ApplicativeAskLaws[F, E]
15 15
16 -
  def applicativeAsk[A: Arbitrary](implicit
17 -
                                   ArbFA: Arbitrary[F[A]],
18 -
                                   ArbE: Arbitrary[E],
19 -
                                   CogenA: Cogen[A],
20 -
                                   CogenE: Cogen[E],
21 -
                                   EqFU: Eq[F[E]],
22 -
                                   EqFA: Eq[F[A]]
23 -
                                  ): RuleSet = {
16 +
  def applicativeAsk[A: Arbitrary](
17 +
      implicit ArbFA: Arbitrary[F[A]],
18 +
      ArbE: Arbitrary[E],
19 +
      CogenA: Cogen[A],
20 +
      CogenE: Cogen[E],
21 +
      EqFU: Eq[F[E]],
22 +
      EqFA: Eq[F[A]]): RuleSet = {
24 23
    new DefaultRuleSet(
25 24
      name = "applicativeAsk",
26 25
      parent = None,
@@ -38,4 +37,3 @@
Loading
38 37
    }
39 38
  }
40 39
}
41 -

@@ -7,13 +7,11 @@
Loading
7 7
}
8 8
9 9
final class ListenOps[F[_], A](val fa: F[A]) extends AnyVal {
10 -
  def listen[L](implicit listen: FunctorListen[F, L]): F[(A, L)] = {
10 +
  def listen[L](implicit listen: FunctorListen[F, L]): F[(A, L)] =
11 11
    listen.listen(fa)
12 -
  }
13 12
14 -
  def listens[L, B](f: L => B)(implicit listen: FunctorListen[F, L]): F[(A, B)] = {
13 +
  def listens[L, B](f: L => B)(implicit listen: FunctorListen[F, L]): F[(A, B)] =
15 14
    listen.listens(fa)(f)
16 -
  }
17 15
18 16
}
19 17

@@ -4,13 +4,13 @@
Loading
4 4
import cats.data._
5 5
6 6
/**
7 -
 * Encapsulates the notion of a monad, G, which contains all of
8 -
 * the effects of some other monad, F. This means that any effect
9 -
 * of type F[A] can be lifted to G[A], such that both F and G
10 -
 * form monads and the lifting distributes over flatMap and pure.
11 -
 *
7 +
  * Encapsulates the notion of a monad, G, which contains all of
8 +
  * the effects of some other monad, F. This means that any effect
9 +
  * of type F[A] can be lifted to G[A], such that both F and G
10 +
  * form monads and the lifting distributes over flatMap and pure.
11 +
  *
12 12
 * Original idea by Kris Nuttycombe.
13 -
 */
13 +
  */
14 14
trait MonadPartialOrder[F[_], G[_]] extends (F ~> G) {
15 15
  def monadF: Monad[F]
16 16
  def monadG: Monad[G]
@@ -18,51 +18,58 @@
Loading
18 18
19 19
private[mtl] trait MonadPartialOrderInstances {
20 20
21 -
  implicit def monadPartialOrderForStateT[F[_], S](implicit F: Monad[F]): MonadPartialOrder[F, StateT[F, S, *]] =
21 +
  implicit def monadPartialOrderForStateT[F[_], S](
22 +
      implicit F: Monad[F]): MonadPartialOrder[F, StateT[F, S, *]] =
22 23
    new MonadPartialOrder[F, StateT[F, S, *]] {
23 24
      val monadF = F
24 25
      val monadG = IndexedStateT.catsDataMonadForIndexedStateT[F, S]
25 26
      def apply[A](fa: F[A]) = StateT.liftF(fa)
26 27
    }
27 28
28 -
  implicit def monadPartialOrderForKleisli[F[_], R](implicit F: Monad[F]): MonadPartialOrder[F, Kleisli[F, R, *]] =
29 +
  implicit def monadPartialOrderForKleisli[F[_], R](
30 +
      implicit F: Monad[F]): MonadPartialOrder[F, Kleisli[F, R, *]] =
29 31
    new MonadPartialOrder[F, Kleisli[F, R, *]] {
30 32
      val monadF = F
31 33
      val monadG = Kleisli.catsDataMonadForKleisli[F, R]
32 34
      def apply[A](fa: F[A]) = Kleisli.liftF(fa)
33 35
    }
34 36
35 -
  implicit def monadPartialOrderForEitherT[F[_], E](implicit F: Monad[F]): MonadPartialOrder[F, EitherT[F, E, *]] =
37 +
  implicit def monadPartialOrderForEitherT[F[_], E](
38 +
      implicit F: Monad[F]): MonadPartialOrder[F, EitherT[F, E, *]] =
36 39
    new MonadPartialOrder[F, EitherT[F, E, *]] {
37 40
      val monadF = F
38 41
      val monadG = EitherT.catsDataMonadErrorForEitherT[F, E]
39 42
      def apply[A](fa: F[A]) = EitherT.liftF(fa)
40 43
    }
41 44
42 -
  implicit def monadPartialOrderForWriterT[F[_], L: Monoid](implicit F: Monad[F]): MonadPartialOrder[F, WriterT[F, L, *]] =
45 +
  implicit def monadPartialOrderForWriterT[F[_], L: Monoid](
46 +
      implicit F: Monad[F]): MonadPartialOrder[F, WriterT[F, L, *]] =
43 47
    new MonadPartialOrder[F, WriterT[F, L, *]] {
44 48
      val monadF = F
45 49
      val monadG = WriterT.catsDataMonadForWriterT[F, L]
46 50
      def apply[A](fa: F[A]) = WriterT.liftF(fa)
47 51
    }
48 52
49 -
  implicit def monadPartialOrderForOptionT[F[_]](implicit F: Monad[F]): MonadPartialOrder[F, OptionT[F, *]] =
53 +
  implicit def monadPartialOrderForOptionT[F[_]](
54 +
      implicit F: Monad[F]): MonadPartialOrder[F, OptionT[F, *]] =
50 55
    new MonadPartialOrder[F, OptionT[F, *]] {
51 56
      val monadF = F
52 57
      val monadG = OptionT.catsDataMonadForOptionT[F]
53 58
      def apply[A](fa: F[A]) = OptionT.liftF(fa)
54 59
    }
55 60
56 -
  implicit def monadPartialOrderForRWST[F[_], E, L: Monoid, S](implicit F: Monad[F]): MonadPartialOrder[F, RWST[F, E, L, S, *]] =
61 +
  implicit def monadPartialOrderForRWST[F[_], E, L: Monoid, S](
62 +
      implicit F: Monad[F]): MonadPartialOrder[F, RWST[F, E, L, S, *]] =
57 63
    new MonadPartialOrder[F, RWST[F, E, L, S, *]] {
58 64
      val monadF = F
59 65
      val monadG = IndexedReaderWriterStateT.catsDataMonadForRWST[F, E, L, S]
60 66
      def apply[A](fa: F[A]) = RWST.liftF(fa)
61 67
    }
62 68
63 -
  implicit def monadPartialOrderForIorT[F[_], E: Semigroup](implicit F: Monad[F]): MonadPartialOrder[F, IorT[F, E, *]] =
69 +
  implicit def monadPartialOrderForIorT[F[_], E: Semigroup](
70 +
      implicit F: Monad[F]): MonadPartialOrder[F, IorT[F, E, *]] =
64 71
    new MonadPartialOrder[F, IorT[F, E, *]] {
65 -
      def apply[A](fa: F[A]): IorT[F,E,A] = IorT.liftF(fa)
72 +
      def apply[A](fa: F[A]): IorT[F, E, A] = IorT.liftF(fa)
66 73
      val monadF: Monad[F] = F
67 74
      val monadG: Monad[IorT[F, E, *]] = IorT.catsDataMonadErrorForIorT[F, E]
68 75
    }

@@ -13,13 +13,12 @@
Loading
13 13
14 14
  def laws: MonadStateLaws[F, S] = MonadStateLaws[F, S]
15 15
16 -
  def monadState[A: Arbitrary](implicit
17 -
                               ArbFA: Arbitrary[F[A]],
18 -
                               ArbS: Arbitrary[S],
19 -
                               CogenS: Cogen[S],
20 -
                               EqFU: Eq[F[Unit]],
21 -
                               EqFS: Eq[F[S]]
22 -
                              ): RuleSet = {
16 +
  def monadState[A: Arbitrary](
17 +
      implicit ArbFA: Arbitrary[F[A]],
18 +
      ArbS: Arbitrary[S],
19 +
      CogenS: Cogen[S],
20 +
      EqFU: Eq[F[Unit]],
21 +
      EqFS: Eq[F[S]]): RuleSet = {
23 22
    new DefaultRuleSet(
24 23
      name = "monadState",
25 24
      parent = None,

@@ -13,14 +13,12 @@
Loading
13 13
  implicit val applicative: Applicative[F] = askInstance.applicative
14 14
15 15
  // external law:
16 -
  def askAddsNoEffects[A](fa: F[A]): IsEq[F[A]] = {
16 +
  def askAddsNoEffects[A](fa: F[A]): IsEq[F[A]] =
17 17
    ask *> fa <-> fa
18 -
  }
19 18
20 19
  // internal law:
21 -
  def readerIsAskAndMap[A](f: E => A): IsEq[F[A]] = {
20 +
  def readerIsAskAndMap[A](f: E => A): IsEq[F[A]] =
22 21
    ask.map(f) <-> reader(f)
23 -
  }
24 22
}
25 23
26 24
object ApplicativeAskLaws {

@@ -20,7 +20,8 @@
Loading
20 20
21 21
private[mtl] trait ApplicativeHandleInstances {
22 22
23 -
  implicit final def handleEitherT[M[_], E](implicit M: Monad[M]): ApplicativeHandle[EitherTC[M, E]#l, E] = {
23 +
  implicit final def handleEitherT[M[_], E](
24 +
      implicit M: Monad[M]): ApplicativeHandle[EitherTC[M, E]#l, E] = {
24 25
    new ApplicativeHandle[EitherTC[M, E]#l, E] {
25 26
      val applicative: Applicative[EitherTC[M, E]#l] = EitherT.catsDataMonadErrorForEitherT(M)
26 27
@@ -38,20 +39,23 @@
Loading
38 39
39 40
  implicit final def handleEither[E]: ApplicativeHandle[EitherC[E]#l, E] = {
40 41
    new ApplicativeHandle[EitherC[E]#l, E] {
41 -
      val applicative: Applicative[EitherC[E]#l] = cats.instances.either.catsStdInstancesForEither[E]
42 +
      val applicative: Applicative[EitherC[E]#l] =
43 +
        cats.instances.either.catsStdInstancesForEither[E]
42 44
43 45
      val functor: Functor[EitherC[E]#l] = cats.instances.either.catsStdInstancesForEither
44 46
45 47
      def raise[A](e: E): Either[E, A] = Left(e)
46 48
47 -
      def handleWith[A](fa: Either[E, A])(f: E => Either[E, A]): Either[E, A] = fa match {
48 -
        case Left(e) => f(e)
49 -
        case r @ Right(_) => r
50 -
      }
49 +
      def handleWith[A](fa: Either[E, A])(f: E => Either[E, A]): Either[E, A] =
50 +
        fa match {
51 +
          case Left(e) => f(e)
52 +
          case r @ Right(_) => r
53 +
        }
51 54
    }
52 55
  }
53 56
54 -
  implicit final def handleOptionT[M[_]](implicit M: Monad[M]): ApplicativeHandle[OptionTC[M]#l, Unit] = {
57 +
  implicit final def handleOptionT[M[_]](
58 +
      implicit M: Monad[M]): ApplicativeHandle[OptionTC[M]#l, Unit] = {
55 59
    new ApplicativeHandle[OptionTC[M]#l, Unit] {
56 60
      val applicative: Applicative[OptionTC[M]#l] = OptionT.catsDataMonadForOptionT(M)
57 61
@@ -75,28 +79,34 @@
Loading
75 79
76 80
      def raise[A](e: Unit): Option[A] = None
77 81
78 -
      def handleWith[A](fa: Option[A])(f: Unit => Option[A]): Option[A] = fa match {
79 -
        case None => f(())
80 -
        case s @ Some(_) => s
81 -
      }
82 +
      def handleWith[A](fa: Option[A])(f: Unit => Option[A]): Option[A] =
83 +
        fa match {
84 +
          case None => f(())
85 +
          case s @ Some(_) => s
86 +
        }
82 87
    }
83 88
  }
84 89
85 -
  implicit final def handleValidated[E](implicit E: Semigroup[E]): ApplicativeHandle[Validated[E, ?], E] =
90 +
  implicit final def handleValidated[E](
91 +
      implicit E: Semigroup[E]): ApplicativeHandle[Validated[E, ?], E] =
86 92
    new ApplicativeHandle[Validated[E, ?], E] {
87 -
      val applicative: Applicative[Validated[E, ?]] = Validated.catsDataApplicativeErrorForValidated[E]
93 +
      val applicative: Applicative[Validated[E, ?]] =
94 +
        Validated.catsDataApplicativeErrorForValidated[E]
88 95
89 96
      val functor: Functor[Validated[E, ?]] = Validated.catsDataApplicativeErrorForValidated[E]
90 97
91 98
      def raise[A](e: E): Validated[E, A] = Validated.Invalid(e)
92 99
93 -
      def handleWith[A](fa: Validated[E, A])(f: E => Validated[E, A]): Validated[E, A] = fa match {
94 -
        case Validated.Invalid(e) => f(e)
95 -
        case v @ Validated.Valid(_) => v
96 -
      }
100 +
      def handleWith[A](fa: Validated[E, A])(f: E => Validated[E, A]): Validated[E, A] =
101 +
        fa match {
102 +
          case Validated.Invalid(e) => f(e)
103 +
          case v @ Validated.Valid(_) => v
104 +
        }
97 105
    }
98 106
99 -
  implicit final def handleIorT[F[_], E](implicit E: Semigroup[E], F: Monad[F]): ApplicativeHandle[IorT[F, E, *], E] =
107 +
  implicit final def handleIorT[F[_], E](
108 +
      implicit E: Semigroup[E],
109 +
      F: Monad[F]): ApplicativeHandle[IorT[F, E, *], E] =
100 110
    new ApplicativeHandle[IorT[F, E, *], E] {
101 111
      val applicative: Applicative[IorT[F, E, ?]] = IorT.catsDataMonadErrorForIorT[F, E]
102 112
@@ -104,12 +114,13 @@
Loading
104 114
105 115
      def raise[A](e: E): IorT[F, E, A] = IorT.leftT(e)
106 116
107 -
      def handleWith[A](fa: IorT[F, E, A])(f: E => IorT[F, E, A]): IorT[F, E, A] = IorT(F.flatMap(fa.value) {
108 -
        case Ior.Left(e) => f(e).value
109 -
        case e @ _ => F.pure(e)
110 -
      })
117 +
      def handleWith[A](fa: IorT[F, E, A])(f: E => IorT[F, E, A]): IorT[F, E, A] =
118 +
        IorT(F.flatMap(fa.value) {
119 +
          case Ior.Left(e) => f(e).value
120 +
          case e @ _ => F.pure(e)
121 +
        })
111 122
    }
112 -
  
123 +
113 124
  implicit final def handleIor[E](implicit E: Semigroup[E]): ApplicativeHandle[Ior[E, *], E] =
114 125
    new ApplicativeHandle[Ior[E, *], E] {
115 126
      val applicative: Applicative[Ior[E, ?]] = Ior.catsDataMonadErrorForIor[E]
@@ -118,56 +129,76 @@
Loading
118 129
119 130
      def raise[A](e: E): Ior[E, A] = Ior.Left(e)
120 131
121 -
      def handleWith[A](fa: Ior[E, A])(f: E => Ior[E, A]): Ior[E, A] = fa match {
122 -
        case Ior.Left(e) => f(e)
123 -
        case _ => fa
124 -
      }
132 +
      def handleWith[A](fa: Ior[E, A])(f: E => Ior[E, A]): Ior[E, A] =
133 +
        fa match {
134 +
          case Ior.Left(e) => f(e)
135 +
          case _ => fa
136 +
        }
125 137
    }
126 138
127 -
  implicit final def applicativeHandleKleisli[F[_], E, R](implicit F0: ApplicativeHandle[F, E], M: Monad[F]): ApplicativeHandle[Kleisli[F, R, *], E] =
128 -
    new ApplicativeHandle[Kleisli[F, R, *], E] with FunctorRaiseMonadPartialOrder[F, Kleisli[F, R, *], E] {
139 +
  implicit final def applicativeHandleKleisli[F[_], E, R](
140 +
      implicit F0: ApplicativeHandle[F, E],
141 +
      M: Monad[F]): ApplicativeHandle[Kleisli[F, R, *], E] =
142 +
    new ApplicativeHandle[Kleisli[F, R, *], E]
143 +
      with FunctorRaiseMonadPartialOrder[F, Kleisli[F, R, *], E] {
129 144
      val applicative: Applicative[Kleisli[F, R, *]] = Kleisli.catsDataMonadForKleisli[F, R]
130 145
131 -
      val F: FunctorRaise[F,E] = F0
132 -
      val lift: MonadPartialOrder[F, Kleisli[F, R, *]] = MonadPartialOrder.monadPartialOrderForKleisli[F, R]
146 +
      val F: FunctorRaise[F, E] = F0
147 +
      val lift: MonadPartialOrder[F, Kleisli[F, R, *]] =
148 +
        MonadPartialOrder.monadPartialOrderForKleisli[F, R]
133 149
134 -
      def handleWith[A](fa: Kleisli[F,R,A])(f: E => Kleisli[F,R,A]): Kleisli[F,R,A] = 
150 +
      def handleWith[A](fa: Kleisli[F, R, A])(f: E => Kleisli[F, R, A]): Kleisli[F, R, A] =
135 151
        Kleisli(r => F0.handleWith(fa.run(r))(e => f(e).run(r)))
136 152
    }
137 153
138 154
  implicit final def applicativeHandleWriterT[F[_], E, L](
139 -
      implicit F0: ApplicativeHandle[F, E], 
140 -
      M: Monad[F], 
155 +
      implicit F0: ApplicativeHandle[F, E],
156 +
      M: Monad[F],
141 157
      L: Monoid[L]): ApplicativeHandle[WriterT[F, L, *], E] =
142 -
    new ApplicativeHandle[WriterT[F, L, *], E] with FunctorRaiseMonadPartialOrder[F, WriterT[F, L, *], E] {
143 -
      val applicative: Applicative[WriterT[F, L, *]] = WriterT.catsDataApplicativeForWriterT[F, L]
158 +
    new ApplicativeHandle[WriterT[F, L, *], E]
159 +
      with FunctorRaiseMonadPartialOrder[F, WriterT[F, L, *], E] {
160 +
      val applicative: Applicative[WriterT[F, L, *]] =
161 +
        WriterT.catsDataApplicativeForWriterT[F, L]
144 162
145 -
      val F: FunctorRaise[F,E] = F0
146 -
      val lift: MonadPartialOrder[F, WriterT[F, L, *]] = MonadPartialOrder.monadPartialOrderForWriterT[F, L]
163 +
      val F: FunctorRaise[F, E] = F0
164 +
      val lift: MonadPartialOrder[F, WriterT[F, L, *]] =
165 +
        MonadPartialOrder.monadPartialOrderForWriterT[F, L]
147 166
148 -
      def handleWith[A](fa: WriterT[F,L,A])(f: E => WriterT[F,L,A]): WriterT[F,L,A] = 
167 +
      def handleWith[A](fa: WriterT[F, L, A])(f: E => WriterT[F, L, A]): WriterT[F, L, A] =
149 168
        WriterT(F0.handleWith(fa.run)(e => f(e).run))
150 169
    }
151 170
152 -
  implicit final def applicativeHandleStateT[F[_], E, S](implicit F0: ApplicativeHandle[F, E], M: Monad[F]): ApplicativeHandle[StateT[F, S, *], E] =
153 -
    new ApplicativeHandle[StateT[F, S, *], E] with FunctorRaiseMonadPartialOrder[F, StateT[F, S, *], E] {
154 -
      val applicative: Applicative[StateT[F, S, *]] = IndexedStateT.catsDataMonadForIndexedStateT[F, S]
171 +
  implicit final def applicativeHandleStateT[F[_], E, S](
172 +
      implicit F0: ApplicativeHandle[F, E],
173 +
      M: Monad[F]): ApplicativeHandle[StateT[F, S, *], E] =
174 +
    new ApplicativeHandle[StateT[F, S, *], E]
175 +
      with FunctorRaiseMonadPartialOrder[F, StateT[F, S, *], E] {
176 +
      val applicative: Applicative[StateT[F, S, *]] =
177 +
        IndexedStateT.catsDataMonadForIndexedStateT[F, S]
155 178
156 -
      val F: FunctorRaise[F,E] = F0
157 -
      val lift: MonadPartialOrder[F, StateT[F, S, *]] = MonadPartialOrder.monadPartialOrderForStateT[F, S]
179 +
      val F: FunctorRaise[F, E] = F0
180 +
      val lift: MonadPartialOrder[F, StateT[F, S, *]] =
181 +
        MonadPartialOrder.monadPartialOrderForStateT[F, S]
158 182
159 -
      def handleWith[A](fa: StateT[F,S,A])(f: E => StateT[F,S,A]): StateT[F,S,A] = 
183 +
      def handleWith[A](fa: StateT[F, S, A])(f: E => StateT[F, S, A]): StateT[F, S, A] =
160 184
        StateT(s => F0.handleWith(fa.run(s))(e => f(e).run(s)))
161 185
    }
162 186
163 -
  implicit final def applicativeHandleRWST[F[_], E, R, L, S](implicit F0: ApplicativeHandle[F, E], M: Monad[F], L: Monoid[L]): ApplicativeHandle[RWST[F, R, L, S, *], E] =
164 -
    new ApplicativeHandle[RWST[F, R, L, S, *], E] with FunctorRaiseMonadPartialOrder[F, RWST[F, R, L, S, *], E] {
165 -
      val applicative: Applicative[RWST[F, R, L, S, *]] = IndexedReaderWriterStateT.catsDataMonadForRWST
166 -
167 -
      val F: FunctorRaise[F,E] = F0
168 -
      val lift: MonadPartialOrder[F, RWST[F, R, L, S, *]] = MonadPartialOrder.monadPartialOrderForRWST
169 -
170 -
      def handleWith[A](fa: RWST[F, R, L, S, A])(f: E => RWST[F, R, L, S, A]): RWST[F, R, L, S, A] = 
187 +
  implicit final def applicativeHandleRWST[F[_], E, R, L, S](
188 +
      implicit F0: ApplicativeHandle[F, E],
189 +
      M: Monad[F],
190 +
      L: Monoid[L]): ApplicativeHandle[RWST[F, R, L, S, *], E] =
191 +
    new ApplicativeHandle[RWST[F, R, L, S, *], E]
192 +
      with FunctorRaiseMonadPartialOrder[F, RWST[F, R, L, S, *], E] {
193 +
      val applicative: Applicative[RWST[F, R, L, S, *]] =
194 +
        IndexedReaderWriterStateT.catsDataMonadForRWST
195 +
196 +
      val F: FunctorRaise[F, E] = F0
197 +
      val lift: MonadPartialOrder[F, RWST[F, R, L, S, *]] =
198 +
        MonadPartialOrder.monadPartialOrderForRWST
199 +
200 +
      def handleWith[A](fa: RWST[F, R, L, S, A])(
201 +
          f: E => RWST[F, R, L, S, A]): RWST[F, R, L, S, A] =
171 202
        RWST { case (r, s) => F0.handleWith(fa.run(r, s))(e => f(e).run(r, s)) }
172 203
    }
173 204
}

@@ -1,7 +1,17 @@
Loading
1 1
package cats
2 2
package mtl
3 3
4 -
import cats.data.{IndexedStateT, IndexedReaderWriterStateT, WriterT, Kleisli, StateT, OptionT, EitherT, IorT, ReaderWriterStateT => RWST}
4 +
import cats.data.{
5 +
  IndexedStateT,
6 +
  IndexedReaderWriterStateT,
7 +
  WriterT,
8 +
  Kleisli,
9 +
  StateT,
10 +
  OptionT,
11 +
  EitherT,
12 +
  IorT,
13 +
  ReaderWriterStateT => RWST
14 +
}
5 15
import cats.implicits._
6 16
7 17
trait ApplicativeCensor[F[_], L] extends FunctorListen[F, L] {
@@ -19,7 +29,10 @@
Loading
19 29
}
20 30
21 31
private[mtl] trait LowPriorityApplicativeCensorInstances {
22 -
  implicit final def inductiveApplicativeCensorWriterT[M[_]: Applicative, L0: Monoid, L: Monoid](implicit A: ApplicativeCensor[M, L]): ApplicativeCensor[WriterT[M, L0, *], L] =
32 +
  implicit final def inductiveApplicativeCensorWriterT[
33 +
      M[_]: Applicative,
34 +
      L0: Monoid,
35 +
      L: Monoid](implicit A: ApplicativeCensor[M, L]): ApplicativeCensor[WriterT[M, L0, *], L] =
23 36
    new FunctorListenInductiveWriterT[M, L0, L] with ApplicativeCensor[WriterT[M, L0, *], L] {
24 37
      val applicative: Applicative[WriterT[M, L0, *]] = WriterT.catsDataApplicativeForWriterT
25 38
      val monoid: Monoid[L] = Monoid[L]
@@ -28,9 +41,12 @@
Loading
28 41
        WriterT(A.censor(fa.run)(f))
29 42
    }
30 43
31 -
  implicit final def inductiveApplicativeCensorRWST[M[_]: Monad, R, L0: Monoid, L: Monoid, S](implicit A: ApplicativeCensor[M, L]): ApplicativeCensor[RWST[M, R, L0, S, *], L] =
32 -
    new FunctorListenInductiveRWST[M, R, L0, L, S] with ApplicativeCensor[RWST[M, R, L0, S, *], L] {
33 -
      val applicative: Applicative[RWST[M, R, L0, S, *]] = IndexedReaderWriterStateT.catsDataMonadForRWST
44 +
  implicit final def inductiveApplicativeCensorRWST[M[_]: Monad, R, L0: Monoid, L: Monoid, S](
45 +
      implicit A: ApplicativeCensor[M, L]): ApplicativeCensor[RWST[M, R, L0, S, *], L] =
46 +
    new FunctorListenInductiveRWST[M, R, L0, L, S]
47 +
      with ApplicativeCensor[RWST[M, R, L0, S, *], L] {
48 +
      val applicative: Applicative[RWST[M, R, L0, S, *]] =
49 +
        IndexedReaderWriterStateT.catsDataMonadForRWST
34 50
      val monoid: Monoid[L] = Monoid[L]
35 51
36 52
      def censor[A](fa: RWST[M, R, L0, S, A])(f: L => L): RWST[M, R, L0, S, A] =
@@ -39,7 +55,9 @@
Loading
39 55
}
40 56
41 57
private[mtl] trait ApplicativeCensorInstances extends LowPriorityApplicativeCensorInstances {
42 -
  implicit final def applicativeCensorWriterT[M[_], L](implicit M: Applicative[M], L: Monoid[L]): ApplicativeCensor[WriterT[M, L, *], L] =
58 +
  implicit final def applicativeCensorWriterT[M[_], L](
59 +
      implicit M: Applicative[M],
60 +
      L: Monoid[L]): ApplicativeCensor[WriterT[M, L, *], L] =
43 61
    new FunctorListenWriterT[M, L] with ApplicativeCensor[WriterT[M, L, *], L] {
44 62
      val applicative: Applicative[WriterT[M, L, *]] =
45 63
        cats.data.WriterT.catsDataApplicativeForWriterT[M, L]
@@ -54,7 +72,9 @@
Loading
54 72
55 73
    }
56 74
57 -
  implicit final def applicativeCensorRWST[M[_], R, L, S](implicit L: Monoid[L], M: Monad[M]): ApplicativeCensor[RWST[M, R, L, S, *], L] =
75 +
  implicit final def applicativeCensorRWST[M[_], R, L, S](
76 +
      implicit L: Monoid[L],
77 +
      M: Monad[M]): ApplicativeCensor[RWST[M, R, L, S, *], L] =
58 78
    new FunctorListenRWST[M, R, L, S] with ApplicativeCensor[RWST[M, R, L, S, *], L] {
59 79
      val applicative: Applicative[RWST[M, R, L, S, *]] =
60 80
        IndexedReaderWriterStateT.catsDataMonadForRWST
@@ -62,57 +82,73 @@
Loading
62 82
      val monoid: Monoid[L] = L
63 83
64 84
      def censor[A](faf: RWST[M, R, L, S, A])(f: L => L): RWST[M, R, L, S, A] =
65 -
        RWST((e, s) => faf.run(e, s).map {
66 -
          case (l, s, a) => (f(l), s, a)
67 -
        })
85 +
        RWST((e, s) =>
86 +
          faf.run(e, s).map {
87 +
            case (l, s, a) => (f(l), s, a)
88 +
          })
68 89
69 90
    }
70 -
  
71 -
  implicit final def applicativeCensorKleisli[F[_], R, L](implicit L: Monoid[L], A: ApplicativeCensor[F, L], F: Applicative[F]): ApplicativeCensor[Kleisli[F, R, *], L] =
91 +
92 +
  implicit final def applicativeCensorKleisli[F[_], R, L](
93 +
      implicit L: Monoid[L],
94 +
      A: ApplicativeCensor[F, L],
95 +
      F: Applicative[F]): ApplicativeCensor[Kleisli[F, R, *], L] =
72 96
    new FunctorListenKleisli[F, R, L] with ApplicativeCensor[Kleisli[F, R, *], L] {
73 -
      val applicative: Applicative[Kleisli[F,R,*]] = Kleisli.catsDataApplicativeForKleisli
97 +
      val applicative: Applicative[Kleisli[F, R, *]] = Kleisli.catsDataApplicativeForKleisli
74 98
      val monoid: cats.Monoid[L] = L
75 99
76 -
      def censor[A](fa: Kleisli[F,R,A])(f: L => L): Kleisli[F,R,A] = 
100 +
      def censor[A](fa: Kleisli[F, R, A])(f: L => L): Kleisli[F, R, A] =
77 101
        Kleisli(r => A.censor(fa.run(r))(f))
78 102
    }
79 -
  
80 -
  implicit final def applicativeCensorStateT[F[_], S, L](implicit L: Monoid[L], A: ApplicativeCensor[F, L], F: Monad[F]): ApplicativeCensor[StateT[F, S, *], L] =
103 +
104 +
  implicit final def applicativeCensorStateT[F[_], S, L](
105 +
      implicit L: Monoid[L],
106 +
      A: ApplicativeCensor[F, L],
107 +
      F: Monad[F]): ApplicativeCensor[StateT[F, S, *], L] =
81 108
    new FunctorListenStateT[F, S, L] with ApplicativeCensor[StateT[F, S, *], L] {
82 -
      val applicative: Applicative[StateT[F,S,*]] = IndexedStateT.catsDataMonadForIndexedStateT
109 +
      val applicative: Applicative[StateT[F, S, *]] =
110 +
        IndexedStateT.catsDataMonadForIndexedStateT
83 111
      val monoid: cats.Monoid[L] = L
84 112
85 -
      def censor[A](fa: StateT[F,S,A])(f: L => L): StateT[F,S,A] = 
113 +
      def censor[A](fa: StateT[F, S, A])(f: L => L): StateT[F, S, A] =
86 114
        StateT(s => A.censor(fa.run(s))(f))
87 115
    }
88 116
89 -
  implicit final def applicativeCensorEitherT[F[_], E, L](implicit L: Monoid[L], A: ApplicativeCensor[F, L], F: Monad[F]): ApplicativeCensor[EitherT[F, E, *], L] =
117 +
  implicit final def applicativeCensorEitherT[F[_], E, L](
118 +
      implicit L: Monoid[L],
119 +
      A: ApplicativeCensor[F, L],
120 +
      F: Monad[F]): ApplicativeCensor[EitherT[F, E, *], L] =
90 121
    new FunctorListenEitherT[F, E, L] with ApplicativeCensor[EitherT[F, E, *], L] {
91 -
      val applicative: Applicative[EitherT[F,E,*]] = EitherT.catsDataMonadErrorForEitherT
122 +
      val applicative: Applicative[EitherT[F, E, *]] = EitherT.catsDataMonadErrorForEitherT
92 123
      val monoid: cats.Monoid[L] = L
93 124
94 -
      def censor[A](fa: EitherT[F,E,A])(f: L => L): EitherT[F,E,A] = 
125 +
      def censor[A](fa: EitherT[F, E, A])(f: L => L): EitherT[F, E, A] =
95 126
        EitherT(A.censor(fa.value)(f))
96 127
    }
97 128
98 -
  implicit final def applicativeCensorIorT[F[_], E, L](implicit L: Monoid[L], A: ApplicativeCensor[F, L], F: Monad[F], E: Semigroup[E]): ApplicativeCensor[IorT[F, E, *], L] =
129 +
  implicit final def applicativeCensorIorT[F[_], E, L](
130 +
      implicit L: Monoid[L],
131 +
      A: ApplicativeCensor[F, L],
132 +
      F: Monad[F],
133 +
      E: Semigroup[E]): ApplicativeCensor[IorT[F, E, *], L] =
99 134
    new FunctorListenIorT[F, E, L] with ApplicativeCensor[IorT[F, E, *], L] {
100 -
      val applicative: Applicative[IorT[F,E,*]] = IorT.catsDataMonadErrorForIorT
135 +
      val applicative: Applicative[IorT[F, E, *]] = IorT.catsDataMonadErrorForIorT
101 136
      val monoid: cats.Monoid[L] = L
102 137
103 -
      def censor[A](fa: IorT[F,E,A])(f: L => L): IorT[F,E,A] = 
138 +
      def censor[A](fa: IorT[F, E, A])(f: L => L): IorT[F, E, A] =
104 139
        IorT(A.censor(fa.value)(f))
105 140
    }
106 141
107 -
  implicit final def applicativeCensorOptionT[F[_], L](implicit L: Monoid[L], A: ApplicativeCensor[F, L], F: Monad[F]): ApplicativeCensor[OptionT[F, *], L] =
142 +
  implicit final def applicativeCensorOptionT[F[_], L](
143 +
      implicit L: Monoid[L],
144 +
      A: ApplicativeCensor[F, L],
145 +
      F: Monad[F]): ApplicativeCensor[OptionT[F, *], L] =
108 146
    new FunctorListenOptionT[F, L] with ApplicativeCensor[OptionT[F, *], L] {
109 -
      val applicative: Applicative[OptionT[F,*]] = OptionT.catsDataMonadForOptionT
147 +
      val applicative: Applicative[OptionT[F, *]] = OptionT.catsDataMonadForOptionT
110 148
      val monoid: cats.Monoid[L] = L
111 149
112 -
      def censor[A](fa: OptionT[F,A])(f: L => L): OptionT[F,A] = 
150 +
      def censor[A](fa: OptionT[F, A])(f: L => L): OptionT[F, A] =
113 151
        OptionT(A.censor(fa.value)(f))
114 152
    }
115 153
116 154
}
117 -
118 -

@@ -3,7 +3,7 @@
Loading
3 3
package syntax
4 4
5 5
trait AskSyntax {
6 -
  implicit def toReaderOps[E, A](fun: E => A): ReaderOps[E, A]  = new ReaderOps(fun)
6 +
  implicit def toReaderOps[E, A](fun: E => A): ReaderOps[E, A] = new ReaderOps(fun)
7 7
}
8 8
9 9
final class ReaderOps[E, A](val fun: E => A) extends AnyVal {

@@ -4,36 +4,36 @@
Loading
4 4
import cats.data.{ReaderWriterStateT => RWST, StateT}
5 5
6 6
/**
7 -
 * `MonadState[F, S]` is the capability to access and modify a state value
8 -
 * from inside the `F[_]` context, using `set(s: S): F[Unit]` and `get: F[S]`.
9 -
 *
7 +
  * `MonadState[F, S]` is the capability to access and modify a state value
8 +
  * from inside the `F[_]` context, using `set(s: S): F[Unit]` and `get: F[S]`.
9 +
  *
10 10
 * MonadState has four external laws:
11 -
 * {{{
12 -
 * def getThenSetDoesNothing = {
13 -
 *   get >>= set <-> pure(())
14 -
 * }
15 -
 * def setThenGetReturnsSetted(s: S) = {
16 -
 *   set(s) *> get <-> set(s) *> pure(s)
17 -
 * }
18 -
 * def setThenSetSetsLast(s1: S, s2: S) = {
19 -
 *   set(s1) *> set(s2) <-> set(s2)
20 -
 * }
21 -
 * def getThenGetGetsOnce = {
22 -
 *   get *> get <-> get
23 -
 * }
24 -
 * }}}
25 -
 *
11 +
  * {{{
12 +
  * def getThenSetDoesNothing = {
13 +
  *   get >>= set <-> pure(())
14 +
  * }
15 +
  * def setThenGetReturnsSetted(s: S) = {
16 +
  *   set(s) *> get <-> set(s) *> pure(s)
17 +
  * }
18 +
  * def setThenSetSetsLast(s1: S, s2: S) = {
19 +
  *   set(s1) *> set(s2) <-> set(s2)
20 +
  * }
21 +
  * def getThenGetGetsOnce = {
22 +
  *   get *> get <-> get
23 +
  * }
24 +
  * }}}
25 +
  *
26 26
 * `MonadState` has two internal law:
27 -
 * {{{
28 -
 * def modifyIsGetThenSet(f: S => S) = {
29 -
 *   modify(f) <-> (inspect(f) flatMap set)
30 -
 * }
31 -
 *
27 +
  * {{{
28 +
  * def modifyIsGetThenSet(f: S => S) = {
29 +
  *   modify(f) <-> (inspect(f) flatMap set)
30 +
  * }
31 +
  *
32 32
 * def inspectLaw[A](f: S => A) = {
33 -
 *   inspect(f) <-> (get map f)
34 -
 * }
35 -
 * }}}
36 -
 *
33 +
  *   inspect(f) <-> (get map f)
34 +
  * }
35 +
  * }}}
36 +
  *
37 37
 */
38 38
trait MonadState[F[_], S] extends Serializable {
39 39
  def monad: Monad[F]
@@ -50,9 +50,11 @@
Loading
50 50
private[mtl] trait LowPriorityMonadStateInstances {
51 51
52 52
  implicit def monadStateForPartialOrder[F[_], G[_], S](
53 -
      implicit liftF: MonadPartialOrder[F, G],    // NB don't make this the *second* parameter; it won't infer
54 -
      ms: MonadState[F, S])
55 -
      : MonadState[G, S] =
53 +
      implicit liftF: MonadPartialOrder[
54 +
        F,
55 +
        G
56 +
      ], // NB don't make this the *second* parameter; it won't infer
57 +
      ms: MonadState[F, S]): MonadState[G, S] =
56 58
    new MonadState[G, S] {
57 59
      val monad = liftF.monadG
58 60
      def get: G[S] = liftF(ms.get)
@@ -71,7 +73,8 @@
Loading
71 73
      def set(s: S) = StateT.set[F, S](s)
72 74
    }
73 75
74 -
  implicit def monadStateForRWST[F[_]: Monad, E, L: Monoid, S]: MonadState[RWST[F, E, L, S, *], S] =
76 +
  implicit def monadStateForRWST[F[_]: Monad, E, L: Monoid, S]
77 +
      : MonadState[RWST[F, E, L, S, *], S] =
75 78
    new MonadState[RWST[F, E, L, S, *], S] {
76 79
      val monad = Monad[RWST[F, E, L, S, *]]
77 80
@@ -90,7 +93,8 @@
Loading
90 93
91 94
  def setF[F[_]]: setFPartiallyApplied[F] = new setFPartiallyApplied[F]
92 95
93 -
  final private[mtl] class setFPartiallyApplied[F[_]](val dummy: Boolean = false) extends AnyVal {
96 +
  final private[mtl] class setFPartiallyApplied[F[_]](val dummy: Boolean = false)
97 +
      extends AnyVal {
94 98
    @inline def apply[E, A](e: E)(implicit state: MonadState[F, E]): F[Unit] =
95 99
      state.set(e)
96 100
  }

@@ -10,16 +10,15 @@
Loading
10 10
trait FunctorListenTests[F[_], L] extends FunctorTellTests[F, L] {
11 11
  def laws: FunctorListenLaws[F, L]
12 12
13 -
  def functorListen[A: Arbitrary, B: Arbitrary](implicit
14 -
                                                    ArbFA: Arbitrary[F[A]],
15 -
                                                    ArbL: Arbitrary[L],
16 -
                                                    CogenA: Cogen[A],
17 -
                                                    CogenL: Cogen[L],
18 -
                                                    EqFU: Eq[F[Unit]],
19 -
                                                    EqFA: Eq[F[A]],
20 -
                                                    EqFAB: Eq[F[(A, B)]],
21 -
                                                    EqFUL: Eq[F[(Unit, L)]]
22 -
                                                   ): RuleSet = {
13 +
  def functorListen[A: Arbitrary, B: Arbitrary](
14 +
      implicit ArbFA: Arbitrary[F[A]],
15 +
      ArbL: Arbitrary[L],
16 +
      CogenA: Cogen[A],
17 +
      CogenL: Cogen[L],
18 +
      EqFU: Eq[F[Unit]],
19 +
      EqFA: Eq[F[A]],
20 +
      EqFAB: Eq[F[(A, B)]],
21 +
      EqFUL: Eq[F[(Unit, L)]]): RuleSet = {
23 22
    new DefaultRuleSet(
24 23
      name = "functorListen",
25 24
      parent = Some(functorTell[A]),

@@ -30,7 +30,8 @@
Loading
30 30
}
31 31
32 32
object ApplicativeCensorLaws {
33 -
  def apply[F[_], L](implicit instance0: ApplicativeCensor[F, L]): ApplicativeCensorLaws[F, L] = {
33 +
  def apply[F[_], L](
34 +
      implicit instance0: ApplicativeCensor[F, L]): ApplicativeCensorLaws[F, L] = {
34 35
    new ApplicativeCensorLaws[F, L] {
35 36
      def F: ApplicativeCensor[F, L] = instance0
36 37
    }

@@ -7,7 +7,8 @@
Loading
7 7
}
8 8
9 9
final class RaiseOps[E](val e: E) extends AnyVal {
10 -
  def raise[F[_], A](implicit functorRaise: FunctorRaise[F, _ >: E]): F[A] = functorRaise.raise(e)
10 +
  def raise[F[_], A](implicit functorRaise: FunctorRaise[F, _ >: E]): F[A] =
11 +
    functorRaise.raise(e)
11 12
}
12 13
13 14
object raise extends RaiseSyntax

@@ -6,27 +6,27 @@
Loading
6 6
import cats.data.Ior
7 7
8 8
/**
9 -
 * `FunctorListen[F, L]` is a function `F[A] => F[(A, L)]` which exposes some state
10 -
 * that is contained in all `F[A]` values, and can be modified using `tell`.
11 -
 *
9 +
  * `FunctorListen[F, L]` is a function `F[A] => F[(A, L)]` which exposes some state
10 +
  * that is contained in all `F[A]` values, and can be modified using `tell`.
11 +
  *
12 12
 * `FunctorListen` has two external laws:
13 -
 * {{{
14 -
 * def listenRespectsTell(l: L) = {
15 -
 *   listen(tell(l)) <-> tell(l).as(((), l))
16 -
 * }
17 -
 *
13 +
  * {{{
14 +
  * def listenRespectsTell(l: L) = {
15 +
  *   listen(tell(l)) <-> tell(l).as(((), l))
16 +
  * }
17 +
  *
18 18
 * def listenAddsNoEffects(fa: F[A]) = {
19 -
 *   listen(fa).map(_._1) <-> fa
20 -
 * }
21 -
 * }}}
22 -
 *
19 +
  *   listen(fa).map(_._1) <-> fa
20 +
  * }
21 +
  * }}}
22 +
  *
23 23
 * `FunctorListen` has one internal law:
24 -
 * {{{
25 -
 * def listensIsListenThenMap(fa: F[A], f: L => B) = {
26 -
 *   listens(fa)(f) <-> listen(fa).map { case (a, l) => (a, f(l)) }
27 -
 * }
28 -
 * }}}
29 -
 */
24 +
  * {{{
25 +
  * def listensIsListenThenMap(fa: F[A], f: L => B) = {
26 +
  *   listens(fa)(f) <-> listen(fa).map { case (a, l) => (a, f(l)) }
27 +
  * }
28 +
  * }}}
29 +
  */
30 30
trait FunctorListen[F[_], L] extends FunctorTell[F, L] with Serializable {
31 31
32 32
  def listen[A](fa: F[A]): F[(A, L)]
@@ -37,28 +37,34 @@
Loading
37 37
    }
38 38
}
39 39
40 -
41 -
private[mtl] abstract class FunctorListenWriterT[F[_]: Applicative, L] extends FunctorListen[WriterT[F, L, *], L] {
40 +
private[mtl] abstract class FunctorListenWriterT[F[_]: Applicative, L]
41 +
    extends FunctorListen[WriterT[F, L, *], L] {
42 42
  def functor = Functor[WriterT[F, L, *]]
43 43
  def tell(l: L) = WriterT.tell[F, L](l)
44 44
  def listen[A](fa: WriterT[F, L, A]) = fa.listen
45 45
}
46 46
47 -
private[mtl] abstract class FunctorListenEitherT[F[_]: Functor, E, L](implicit F: FunctorListen[F, L]) extends FunctorListen[EitherT[F, E, *], L] {
47 +
private[mtl] abstract class FunctorListenEitherT[F[_]: Functor, E, L](
48 +
    implicit F: FunctorListen[F, L])
49 +
    extends FunctorListen[EitherT[F, E, *], L] {
48 50
  def functor = Functor[EitherT[F, E, *]]
49 51
  def tell(l: L) = EitherT.liftF(F.tell(l))
50 52
  def listen[A](fa: EitherT[F, E, A]) =
51 53
    EitherT(F.listen(fa.value) map { case (e, l) => e.tupleRight(l) })
52 54
}
53 55
54 -
private[mtl] abstract class FunctorListenKleisli[F[_]: Functor, R, L](implicit F: FunctorListen[F, L]) extends FunctorListen[Kleisli[F, R, *], L] {
56 +
private[mtl] abstract class FunctorListenKleisli[F[_]: Functor, R, L](
57 +
    implicit F: FunctorListen[F, L])
58 +
    extends FunctorListen[Kleisli[F, R, *], L] {
55 59
  def functor = Functor[Kleisli[F, R, *]]
56 60
  def tell(l: L) = Kleisli.liftF(F.tell(l))
57 61
  def listen[A](fa: Kleisli[F, R, A]) =
58 62
    Kleisli(a => F.listen(fa.run(a)))
59 63
}
60 64
61 -
private[mtl] abstract class FunctorListenStateT[F[_]: Applicative, S, L](implicit F: FunctorListen[F, L]) extends FunctorListen[StateT[F, S, *], L] {
65 +
private[mtl] abstract class FunctorListenStateT[F[_]: Applicative, S, L](
66 +
    implicit F: FunctorListen[F, L])
67 +
    extends FunctorListen[StateT[F, S, *], L] {
62 68
  def functor = Functor[StateT[F, S, *]]
63 69
  def tell(l: L) = StateT.liftF(F.tell(l))
64 70
  def listen[A](fa: StateT[F, S, A]) =
@@ -72,101 +78,116 @@
Loading
72 78
    }
73 79
}
74 80
75 -
private[mtl] abstract class FunctorListenOptionT[F[_]: Functor, L](implicit F: FunctorListen[F, L]) extends FunctorListen[OptionT[F, *], L] {
81 +
private[mtl] abstract class FunctorListenOptionT[F[_]: Functor, L](
82 +
    implicit F: FunctorListen[F, L])
83 +
    extends FunctorListen[OptionT[F, *], L] {
76 84
  def functor = Functor[OptionT[F, *]]
77 85
  def tell(l: L) = OptionT.liftF(F.tell(l))
78 86
  def listen[A](fa: OptionT[F, A]) =
79 87
    OptionT(F.listen(fa.value) map { case (opt, l) => opt.tupleRight(l) })
80 88
}
81 89
82 -
private[mtl] abstract class FunctorListenIorT[F[_]: Applicative, E, L](implicit F: FunctorListen[F, L]) extends FunctorListen[IorT[F, E, *], L] {
90 +
private[mtl] abstract class FunctorListenIorT[F[_]: Applicative, E, L](
91 +
    implicit F: FunctorListen[F, L])
92 +
    extends FunctorListen[IorT[F, E, *], L] {
83 93
  def functor = Functor[IorT[F, E, *]]
84 94
  def tell(l: L) = IorT.liftF(F.tell(l))
85 -
  def listen[A](fa: IorT[F, E, A]): IorT[F, E, (A, L)] = IorT(F.listen(fa.value).map {
86 -
    case (Ior.Both(e, a), l) => Ior.both(e, (a, l))
87 -
    case (Ior.Left(e), _) => Ior.left(e)
88 -
    case (Ior.Right(a), l) => Ior.right((a, l))
89 -
  })
95 +
  def listen[A](fa: IorT[F, E, A]): IorT[F, E, (A, L)] =
96 +
    IorT(F.listen(fa.value).map {
97 +
      case (Ior.Both(e, a), l) => Ior.both(e, (a, l))
98 +
      case (Ior.Left(e), _) => Ior.left(e)
99 +
      case (Ior.Right(a), l) => Ior.right((a, l))
100 +
    })
90 101
}
91 102
92 -
private[mtl] abstract class FunctorListenRWST[F[_]: Applicative, E, L, S] extends FunctorListen[RWST[F, E, L, S, *], L] {
93 -
    def functor = Functor[RWST[F, E, L, S, *]]
94 -
    def tell(l: L) = RWST.tell(l)
95 -
    def listen[A](fa: RWST[F, E, L, S, A]) =
96 -
      RWST applyF {
97 -
        fa.runF map { f => (e: E, s: S) =>
98 -
          f(e, s) map {
99 -
            case (l, s, a) => (l, s, (a, l))
100 -
          }
103 +
private[mtl] abstract class FunctorListenRWST[F[_]: Applicative, E, L, S]
104 +
    extends FunctorListen[RWST[F, E, L, S, *], L] {
105 +
  def functor = Functor[RWST[F, E, L, S, *]]
106 +
  def tell(l: L) = RWST.tell(l)
107 +
  def listen[A](fa: RWST[F, E, L, S, A]) =
108 +
    RWST applyF {
109 +
      fa.runF map { f => (e: E, s: S) =>
110 +
        f(e, s) map {
111 +
          case (l, s, a) => (l, s, (a, l))
101 112
        }
102 113
      }
103 -
  }
104 -
105 -
private[mtl] abstract class FunctorListenInductiveWriterT[F[_]: Applicative, L0: Monoid, L](implicit F: FunctorListen[F, L]) 
106 -
  extends FunctorListen[WriterT[F, L0, *], L] {
107 -
    def functor = Functor[WriterT[F, L0, *]]
108 -
    def tell(l: L) = WriterT.liftF(F.tell(l))
109 -
    def listen[A](fa: WriterT[F, L0, A]) =
110 -
      WriterT(F.listen(fa.run) map { case ((l0, a), l) => (l0, (a, l)) })
111 -
  }
112 -
113 -
114 -
private[mtl] abstract class FunctorListenInductiveRWST[F[_]: Applicative, E, L0: Monoid, L, S](implicit F: FunctorListen[F, L]) 
115 -
  extends FunctorListen[RWST[F, E, L0, S, *], L] {
116 -
    def functor = Functor[RWST[F, E, L0, S, *]]
117 -
      def tell(l: L) =
118 -
        RWST.liftF[F, E, L0, S, Unit](F.tell(l))
119 -
120 -
      def listen[A](fa: RWST[F, E, L0, S, A]) =
121 -
        RWST applyF {
122 -
          fa.runF map { f => (e: E, s: S) =>
123 -
            F.listen(f(e, s)) map {
124 -
              case ((l0, s, a), l) =>
125 -
                (l0, s, (a, l))
126 -
            }
127 -
          }
128 -
        }
129 -
  }
114 +
    }
115 +
}
130 116
117 +
private[mtl] abstract class FunctorListenInductiveWriterT[F[_]: Applicative, L0: Monoid, L](
118 +
    implicit F: FunctorListen[F, L])
119 +
    extends FunctorListen[WriterT[F, L0, *], L] {
120 +
  def functor = Functor[WriterT[F, L0, *]]
121 +
  def tell(l: L) = WriterT.liftF(F.tell(l))
122 +
  def listen[A](fa: WriterT[F, L0, A]) =
123 +
    WriterT(F.listen(fa.run) map { case ((l0, a), l) => (l0, (a, l)) })
124 +
}
131 125
126 +
private[mtl] abstract class FunctorListenInductiveRWST[F[_]: Applicative, E, L0: Monoid, L, S](
127 +
    implicit F: FunctorListen[F, L])
128 +
    extends FunctorListen[RWST[F, E, L0, S, *], L] {
129 +
  def functor = Functor[RWST[F, E, L0, S, *]]
130 +
  def tell(l: L) =
131 +
    RWST.liftF[F, E, L0, S, Unit](F.tell(l))
132 +
133 +
  def listen[A](fa: RWST[F, E, L0, S, A]) =
134 +
    RWST applyF {
135 +
      fa.runF map { f => (e: E, s: S) =>
136 +
        F.listen(f(e, s)) map {
137 +
          case ((l0, s, a), l) =>
138 +
            (l0, s, (a, l))
139 +
        }
140 +
      }
141 +
    }
142 +
}
132 143
133 144
private[mtl] trait LowPriorityFunctorListenInstances {
134 145
135 146
  implicit def inductiveFunctorListenForWriterT[F[_]: Applicative, L, L0: Monoid](
136 -
      implicit F: FunctorListen[F, L])
137 -
      : FunctorListen[WriterT[F, L0, *], L] =
147 +
      implicit F: FunctorListen[F, L]): FunctorListen[WriterT[F, L0, *], L] =
138 148
    new FunctorListenInductiveWriterT[F, L0, L] {}
139 149
140 -
  implicit def inductiveFunctorListenForRWST[F[_]: Applicative, E, L0: Monoid, S, L](implicit F: FunctorListen[F, L]): FunctorListen[RWST[F, E, L0, S, *], L] =
150 +
  implicit def inductiveFunctorListenForRWST[F[_]: Applicative, E, L0: Monoid, S, L](
151 +
      implicit F: FunctorListen[F, L]): FunctorListen[RWST[F, E, L0, S, *], L] =
141 152
    new FunctorListenInductiveRWST[F, E, L0, L, S] {}
142 153
}
143 154
144 -
private[mtl] trait FunctorListenInstances extends LowPriorityFunctorListenInstances {
155 +
private[mtl] trait FunctorListenInstances
156 +
    extends LowPriorityFunctorListenInstances
157 +
    with LowPriorityFunctorListenInstancesCompat {
145 158
146 -
  implicit def functorListenForEitherT[F[_]: Functor, E, L](implicit F: FunctorListen[F, L]): FunctorListen[EitherT[F, E, *], L] =
159 +
  implicit def functorListenForEitherT[F[_]: Functor, E, L](
160 +
      implicit F: FunctorListen[F, L]): FunctorListen[EitherT[F, E, *], L] =
147 161
    new FunctorListenEitherT[F, E, L] {}
148 162
149 -
  implicit def functorListenForKleisli[F[_]: Functor, R, L](implicit F: FunctorListen[F, L]): FunctorListen[Kleisli[F, R, *], L] =
163 +
  implicit def functorListenForKleisli[F[_]: Functor, R, L](
164 +
      implicit F: FunctorListen[F, L]): FunctorListen[Kleisli[F, R, *], L] =
150 165
    new FunctorListenKleisli[F, R, L] {}
151 166
152 -
  implicit def functorListenForOptionT[F[_]: Functor, L](implicit F: FunctorListen[F, L]): FunctorListen[OptionT[F, *], L] =
167 +
  implicit def functorListenForOptionT[F[_]: Functor, L](
168 +
      implicit F: FunctorListen[F, L]): FunctorListen[OptionT[F, *], L] =
153 169
    new FunctorListenOptionT[F, L] {}
154 170
155 -
  implicit def functorListenForStateT[F[_]: Applicative, S, L](implicit F: FunctorListen[F, L]): FunctorListen[StateT[F, S, *], L] =
171 +
  implicit def functorListenForStateT[F[_]: Applicative, S, L](
172 +
      implicit F: FunctorListen[F, L]): FunctorListen[StateT[F, S, *], L] =
156 173
    new FunctorListenStateT[F, S, L] {}
157 174
158 -
  implicit def baseFunctorListenForWriterT[F[_]: Applicative, L]: FunctorListen[WriterT[F, L, *], L] =
175 +
  implicit def baseFunctorListenForWriterT[F[_]: Applicative, L]
176 +
      : FunctorListen[WriterT[F, L, *], L] =
159 177
    new FunctorListenWriterT[F, L] {}
160 178
161 -
  implicit def functorListenForIorT[F[_]: Applicative, K, L](implicit F: FunctorListen[F, K]): FunctorListen[IorT[F, L, *], K] =
179 +
  implicit def functorListenForIorT[F[_]: Applicative, K, L](
180 +
      implicit F: FunctorListen[F, K]): FunctorListen[IorT[F, L, *], K] =
162 181
    new FunctorListenIorT[F, L, K] {}
163 182
164 -
  implicit def baseFunctorListenForRWST[F[_]: Applicative, E, L, S]: FunctorListen[RWST[F, E, L, S, *], L] =
183 +
  implicit def baseFunctorListenForRWST[F[_]: Applicative, E, L, S]
184 +
      : FunctorListen[RWST[F, E, L, S, *], L] =
165 185
    new FunctorListenRWST[F, E, L, S] {}
166 186
}
167 187
168 188
object FunctorListen extends FunctorListenInstances {
169 189
  def apply[F[_], L](implicit listen: FunctorListen[F, L]): FunctorListen[F, L] = listen
170 190
  def listen[F[_], L, A](fa: F[A])(implicit ev: FunctorListen[F, L]): F[(A, L)] = ev.listen(fa)
171 -
  def listens[F[_], L, A, B](fa: F[A])(f: L => B)(implicit ev: FunctorListen[F, L]): F[(A, B)] = ev.listens(fa)(f)
191 +
  def listens[F[_], L, A, B](fa: F[A])(f: L => B)(implicit ev: FunctorListen[F, L]): F[(A, B)] =
192 +
    ev.listens(fa)(f)
172 193
}

@@ -10,16 +10,15 @@
Loading
10 10
trait ApplicativeCensorTests[F[_], L] extends FunctorListenTests[F, L] {
11 11
  def laws: ApplicativeCensorLaws[F, L]
12 12
13 -
  def applicativeCensor[A: Arbitrary, B: Arbitrary](implicit
14 -
                                                    ArbFA: Arbitrary[F[A]],
15 -
                                                    ArbL: Arbitrary[L],
16 -
                                                    CogenA: Cogen[A],
17 -
                                                    CogenL: Cogen[L],
18 -
                                                    EqFU: Eq[F[Unit]],
19 -
                                                    EqFA: Eq[F[A]],
20 -
                                                    EqFAB: Eq[F[(A, B)]],
21 -
                                                    EqFUL: Eq[F[(Unit, L)]]
22 -
                                                 ): RuleSet = {
13 +
  def applicativeCensor[A: Arbitrary, B: Arbitrary](
14 +
      implicit ArbFA: Arbitrary[F[A]],
15 +
      ArbL: Arbitrary[L],
16 +
      CogenA: Cogen[A],
17 +
      CogenL: Cogen[L],
18 +
      EqFU: Eq[F[Unit]],
19 +
      EqFA: Eq[F[A]],
20 +
      EqFAB: Eq[F[(A, B)]],
21 +
      EqFUL: Eq[F[(Unit, L)]]): RuleSet = {
23 22
    new DefaultRuleSet(
24 23
      name = "applicativeCensor",
25 24
      parent = Some(functorListen[A, B]),
@@ -34,7 +33,8 @@
Loading
34 33
}
35 34
36 35
object ApplicativeCensorTests {
37 -
  def apply[F[_], L](implicit instance0: ApplicativeCensor[F, L]): ApplicativeCensorTests[F, L] = {
36 +
  def apply[F[_], L](
37 +
      implicit instance0: ApplicativeCensor[F, L]): ApplicativeCensorTests[F, L] = {
38 38
    new ApplicativeCensorTests[F, L] {
39 39
      override def laws: ApplicativeCensorLaws[F, L] = ApplicativeCensorLaws[F, L]
40 40
    }

@@ -12,13 +12,12 @@
Loading
12 12
  implicit val raiseInstance: FunctorRaise[F, E]
13 13
  def laws: FunctorRaiseLaws[F, E] = FunctorRaiseLaws[F, E]
14 14
15 -
  def functorRaise[A: Arbitrary](implicit
16 -
                                ArbFA: Arbitrary[F[A]],
17 -
                                ArbE: Arbitrary[E],
18 -
                                CogenA: Cogen[A],
19 -
                                EqFU: Eq[F[Unit]],
20 -
                                EqFA: Eq[F[A]]
21 -
                               ): RuleSet = {
15 +
  def functorRaise[A: Arbitrary](
16 +
      implicit ArbFA: Arbitrary[F[A]],
17 +
      ArbE: Arbitrary[E],
18 +
      CogenA: Cogen[A],
19 +
      EqFU: Eq[F[Unit]],
20 +
      EqFA: Eq[F[A]]): RuleSet = {
22 21
    new DefaultRuleSet(
23 22
      name = "functorRaise",
24 23
      parent = None,

@@ -32,7 +32,8 @@
Loading
32 32
  def reader[A](f: E => A): F[A] = applicative.map(ask)(f)
33 33
}
34 34
35 -
private[mtl] trait ApplicativeAskForMonadPartialOrder[F[_], G[_], E] extends ApplicativeAsk[G, E] {
35 +
private[mtl] trait ApplicativeAskForMonadPartialOrder[F[_], G[_], E]
36 +
    extends ApplicativeAsk[G, E] {
36 37
  val lift: MonadPartialOrder[F, G]
37 38
  val F: ApplicativeAsk[F, E]
38 39
@@ -40,59 +41,61 @@
Loading
40 41
  override def ask = lift(F.ask)
41 42
}
42 43
43 -
private[mtl] trait LowPriorityApplicativeAskInstances extends LowPriorityApplicativeAskInstancesCompat {
44 +
private[mtl] trait LowPriorityApplicativeAskInstances
45 +
    extends LowPriorityApplicativeAskInstancesCompat {
44 46
45 47
  implicit def applicativeAskForMonadPartialOrder[F[_], G[_], E](
46 48
      implicit lift0: MonadPartialOrder[F, G],
47 -
      F0: ApplicativeAsk[F, E])
48 -
      : ApplicativeAsk[G, E] =
49 +
      F0: ApplicativeAsk[F, E]): ApplicativeAsk[G, E] =
49 50
    new ApplicativeAskForMonadPartialOrder[F, G, E] {
50 -
      val lift: MonadPartialOrder[F,G] = lift0
51 -
      val F: ApplicativeAsk[F,E] = F0
51 +
      val lift: MonadPartialOrder[F, G] = lift0
52 +
      val F: ApplicativeAsk[F, E] = F0
52 53
    }
53 54
}
54 55
55 -
56 56
private[mtl] trait ApplicativeAskInstances extends LowPriorityApplicativeAskInstances {
57 57
58 -
  implicit def applicativeAskForKleisli[F[_], E](implicit F: Applicative[F]): ApplicativeAsk[Kleisli[F, E, *], E] =
58 +
  implicit def applicativeAskForKleisli[F[_], E](
59 +
      implicit F: Applicative[F]): ApplicativeAsk[Kleisli[F, E, *], E] =
59 60
    ApplicativeLocal.baseApplicativeLocalForKleisli[F, E]
60 61
61 -
  implicit def applicativeAskForRWST[F[_], E, L, S](implicit F: Monad[F], L: Monoid[L]): ApplicativeAsk[RWST[F, E, L, S, *], E] =
62 +
  implicit def applicativeAskForRWST[F[_], E, L, S](
63 +
      implicit F: Monad[F],
64 +
      L: Monoid[L]): ApplicativeAsk[RWST[F, E, L, S, *], E] =
62 65
    ApplicativeLocal.baseApplicativeLocalForRWST[F, E, L, S]
63 66
}
64 67
65 68
object ApplicativeAsk extends ApplicativeAskInstances {
66 69
67 -
  def apply[F[_], E](implicit applicativeAsk: ApplicativeAsk[F, E]): ApplicativeAsk[F, E] = applicativeAsk
70 +
  def apply[F[_], E](implicit applicativeAsk: ApplicativeAsk[F, E]): ApplicativeAsk[F, E] =
71 +
    applicativeAsk
68 72
69 -
  def const[F[_]: Applicative, E](e: E): ApplicativeAsk[F, E] = new ApplicativeAsk[F, E] {
70 -
    val applicative: Applicative[F] = Applicative[F]
71 -
    val ask: F[E] = applicative.pure(e)
72 -
  }
73 +
  def const[F[_]: Applicative, E](e: E): ApplicativeAsk[F, E] =
74 +
    new ApplicativeAsk[F, E] {
75 +
      val applicative: Applicative[F] = Applicative[F]
76 +
      val ask: F[E] = applicative.pure(e)
77 +
    }
73 78
74 -
  def ask[F[_], E](implicit ask: ApplicativeAsk[F, E]): F[E] = {
79 +
  def ask[F[_], E](implicit ask: ApplicativeAsk[F, E]): F[E] =
75 80
    ask.ask
76 -
  }
77 81
78 82
  def askF[F[_]]: askFPartiallyApplied[F] = new askFPartiallyApplied[F]
79 83
80 -
  @inline final private[mtl] class askFPartiallyApplied[F[_]](val dummy: Boolean = false) extends AnyVal {
81 -
    @inline def apply[E]()(implicit ask: `ApplicativeAsk`[F, E]): F[E] = {
84 +
  @inline final private[mtl] class askFPartiallyApplied[F[_]](val dummy: Boolean = false)
85 +
      extends AnyVal {
86 +
    @inline def apply[E]()(implicit ask: `ApplicativeAsk`[F, E]): F[E] =
82 87
      ask.ask
83 -
    }
84 88
  }
85 89
86 -
  @inline final private[mtl] class readerFEPartiallyApplied[F[_], E](val dummy: Boolean = false) extends AnyVal {
87 -
    @inline def apply[A](f: E => A)(implicit ask: ApplicativeAsk[F, E]): F[A] = {
90 +
  @inline final private[mtl] class readerFEPartiallyApplied[F[_], E](val dummy: Boolean = false)
91 +
      extends AnyVal {
92 +
    @inline def apply[A](f: E => A)(implicit ask: ApplicativeAsk[F, E]): F[A] =
88 93
      ask.reader(f)
89 -
    }
90 94
  }
91 95
92 96
  def readerFE[F[_], E]: readerFEPartiallyApplied[F, E] = new readerFEPartiallyApplied[F, E]
93 97
94 -
  def reader[F[_], E, A](fun: E => A)(implicit ask: ApplicativeAsk[F, E]): F[A] = {
98 +
  def reader[F[_], E, A](fun: E => A)(implicit ask: ApplicativeAsk[F, E]): F[A] =
95 99
    ask.reader(fun)
96 -
  }
97 100
98 101
}

@@ -5,51 +5,44 @@
Loading
5 5
import cats.data.Ior
6 6
7 7
trait ChronicleSyntax {
8 -
  implicit def toChronicleOps[F[_], A](fa: F[A]): ChronicleOps[F, A] = new ChronicleOps[F, A](fa)
8 +
  implicit def toChronicleOps[F[_], A](fa: F[A]): ChronicleOps[F, A] =
9 +
    new ChronicleOps[F, A](fa)
9 10
  implicit def toChronicleIdOps[E](e: E): ChronicleIdOps[E] = new ChronicleIdOps[E](e)
10 -
  implicit def toChronicleIorOps[A, E](ior: E Ior A): ChronicleIorOps[A, E] = new ChronicleIorOps[A, E](ior)
11 +
  implicit def toChronicleIorOps[A, E](ior: E Ior A): ChronicleIorOps[A, E] =
12 +
    new ChronicleIorOps[A, E](ior)
11 13
}
12 14
13 15
final class ChronicleOps[F[_], A](val fa: F[A]) extends AnyVal {
14 -
  def materialize[E](implicit chronicle: MonadChronicle[F, E]): F[E Ior A] = {
16 +
  def materialize[E](implicit chronicle: MonadChronicle[F, E]): F[E Ior A] =
15 17
    chronicle.materialize(fa)
16 -
  }
17 18
18 -
  def memento[E](implicit chronicle: MonadChronicle[F, E]): F[Either[E, A]] = {
19 +
  def memento[E](implicit chronicle: MonadChronicle[F, E]): F[Either[E, A]] =
19 20
    chronicle.memento(fa)
20 -
  }
21 21
22 -
  def absolve[E](a: => A)(implicit chronicle: MonadChronicle[F, E]): F[A] = {
22 +
  def absolve[E](a: => A)(implicit chronicle: MonadChronicle[F, E]): F[A] =
23 23
    chronicle.absolve(fa)(a)
24 -
  }
25 24
26 -
  def condemn[E](implicit chronicle: MonadChronicle[F, E]): F[A] = {
25 +
  def condemn[E](implicit chronicle: MonadChronicle[F, E]): F[A] =
27 26
    chronicle.condemn(fa)
28 -
  }
29 27
30 -
  def retcon[E](cc: E => E)(implicit chronicle: MonadChronicle[F, E]): F[A] = {
28 +
  def retcon[E](cc: E => E)(implicit chronicle: MonadChronicle[F, E]): F[A] =
31 29
    chronicle.retcon(fa)(cc)
32 -
  }
33 30
}
34 31
35 32
final class ChronicleIdOps[E](val e: E) extends AnyVal {
36 -
  def dictate[F[_]](implicit chronicle: MonadChronicle[F, E]): F[Unit] = {
37 -
      chronicle.dictate(e)
38 -
    }
33 +
  def dictate[F[_]](implicit chronicle: MonadChronicle[F, E]): F[Unit] =
34 +
    chronicle.dictate(e)
39 35
40 -
  def disclose[F[_], A](implicit chronicle: MonadChronicle[F, E], monoid: Monoid[A]): F[A] = {
41 -
      chronicle.disclose(e)
42 -
    }
36 +
  def disclose[F[_], A](implicit chronicle: MonadChronicle[F, E], monoid: Monoid[A]): F[A] =
37 +
    chronicle.disclose(e)
43 38
44 -
  def confess[F[_], A](implicit chronicle: MonadChronicle[F, E]): F[A] = {
45 -
      chronicle.confess(e)
46 -
    }
39 +
  def confess[F[_], A](implicit chronicle: MonadChronicle[F, E]): F[A] =
40 +
    chronicle.confess(e)
47 41
}
48 42
49 43
final class ChronicleIorOps[A, E](val ior: E Ior A) extends AnyVal {
50 -
  def chronicle[F[_]](implicit chronicle: MonadChronicle[F, E]): F[A] = {
44 +
  def chronicle[F[_]](implicit chronicle: MonadChronicle[F, E]): F[A] =
51 45
    chronicle.chronicle(ior)
52 -
  }
53 46
}
54 47
55 48
object chronicle extends ChronicleSyntax

@@ -7,6 +7,7 @@
Loading
7 7
import cats.syntax.functor._
8 8
import cats.syntax.apply._
9 9
import cats.syntax.semigroup._
10 +
10 11
/**
11 12
  * Created by Yuval.Itzchakov on 20/07/2018.
12 13
  */
@@ -17,53 +18,43 @@
Loading
17 18
  import chronicleInstance._
18 19
  import monad._
19 20
20 -
  def dictateThenMaterializeIsBoth(e: E): IsEq[F[E Ior Unit]] = {
21 +
  def dictateThenMaterializeIsBoth(e: E): IsEq[F[E Ior Unit]] =
21 22
    materialize(dictate(e)) <-> pure(Ior.Both(e, ()))
22 -
  }
23 23
24 -
  def confessThenMaterializeIsLeft[A](e: E): IsEq[F[E Ior A]] = {
24 +
  def confessThenMaterializeIsLeft[A](e: E): IsEq[F[E Ior A]] =
25 25
    materialize[A](confess(e)) <-> pure(Ior.Left(e))
26 -
  }
27 26
28 -
  def pureThenMaterializeIsRight[A](a: A): IsEq[F[E Ior A]] = {
27 +
  def pureThenMaterializeIsRight[A](a: A): IsEq[F[E Ior A]] =
29 28
    materialize[A](pure(a)) <-> pure(Ior.Right(a))
30 -
  }
31 29
32 -
  def confessThenAbsolveIsPure[A](a: A, e: E): IsEq[F[A]] = {
30 +
  def confessThenAbsolveIsPure[A](a: A, e: E): IsEq[F[A]] =
33 31
    absolve(confess[A](e))(a) <-> pure(a)
34 -
  }
35 32
36 -
  def dictateThenCondemIsConfess[A](e: E): IsEq[F[Unit]] = {
33 +
  def dictateThenCondemIsConfess[A](e: E): IsEq[F[Unit]] =
37 34
    condemn(dictate(e)) <-> confess(e)
38 -
  }
39 35
40 -
  def confessThenMementoIsLeft[A](e: E): IsEq[F[Either[E, A]]] = {
36 +
  def confessThenMementoIsLeft[A](e: E): IsEq[F[Either[E, A]]] =
41 37
    memento[A](confess(e)) <-> pure(Left(e))
42 -
  }
43 38
44 -
  def dictateThenMementoIsDictateRightUnit(e: E): IsEq[F[Either[E, Unit]]] = {
39 +
  def dictateThenMementoIsDictateRightUnit(e: E): IsEq[F[Either[E, Unit]]] =
45 40
    memento(dictate(e)) <-> dictate(e).map(_ => Right(()))
46 -
  }
47 41
48 -
  def confessThenRetconIsConfess[A](f: E => E, e: E): IsEq[F[A]] = {
42 +
  def confessThenRetconIsConfess[A](f: E => E, e: E): IsEq[F[A]] =
49 43
    retcon(confess[A](e))(f) <-> confess[A](f(e))
50 -
  }
51 44
52 -
  def dictateThenRetconIsDictate[A](f: E => E, e: E): IsEq[F[Unit]] = {
45 +
  def dictateThenRetconIsDictate[A](f: E => E, e: E): IsEq[F[Unit]] =
53 46
    retcon(dictate(e))(f) <-> dictate(f(e))
54 -
  }
55 47
56 -
  def pureThenRetconIsPure[A](f: E => E, a: A): IsEq[F[A]] = {
48 +
  def pureThenRetconIsPure[A](f: E => E, a: A): IsEq[F[A]] =
57 49
    retcon(pure(a))(f) <-> pure(a)
58 -
  }
59 50
60 -
  def dictateSharkDictateIsDictateSemigroup(e0: E, e: E)(implicit ev: Semigroup[E]): IsEq[F[Unit]] = {
51 +
  def dictateSharkDictateIsDictateSemigroup(e0: E, e: E)(
52 +
      implicit ev: Semigroup[E]): IsEq[F[Unit]] =
61 53
    dictate(e0) *> dictate(e) <-> dictate(e0 |+| e)
62 -
  }
63 54
64 -
  def dictateSharkConfessIsConfessSemigroup[A](e0: E, e: E)(implicit ev: Semigroup[E]): IsEq[F[A]] = {
55 +
  def dictateSharkConfessIsConfessSemigroup[A](e0: E, e: E)(
56 +
      implicit ev: Semigroup[E]): IsEq[F[A]] =
65 57
    dictate(e0) *> confess[A](e) <-> confess[A](e0 |+| e)
66 -
  }
67 58
}
68 59
69 60
object MonadChronicleLaws {

@@ -4,21 +4,21 @@
Loading
4 4
import cats.data.WriterT
5 5
6 6
/**
7 -
 * `FunctorTell[F, L]` is the ability to "log" values `L` inside a context `F[_]`, as an effect.
8 -
 *
7 +
  * `FunctorTell[F, L]` is the ability to "log" values `L` inside a context `F[_]`, as an effect.
8 +
  *
9 9
 * `FunctorTell` has no external laws.
10 -
 *
10 +
  *
11 11
 * `FunctorTell` has one internal law:
12 -
 * {{{
13 -
 * def writerIsTellAndMap(a: A, l: L) = {
14 -
 *   (tell(l) as a) <-> writer(a, l)
15 -
 * }
16 -
 *
12 +
  * {{{
13 +
  * def writerIsTellAndMap(a: A, l: L) = {
14 +
  *   (tell(l) as a) <-> writer(a, l)
15 +
  * }
16 +
  *
17 17
 * def tupleIsWriterFlipped(a: A, l: L) = {
18 -
 *   writer(a, l) <-> tuple((l, a))
19 -
 * }
20 -
 * }}}
21 -
 */
18 +
  *   writer(a, l) <-> tuple((l, a))
19 +
  * }
20 +
  * }}}
21 +
  */
22 22
trait FunctorTell[F[_], L] extends Serializable {
23 23
  def functor: Functor[F]
24 24
@@ -41,17 +41,19 @@
Loading
41 41
42 42
  implicit def functorTellForPartialOrder[F[_], G[_], L](
43 43
      implicit lift0: MonadPartialOrder[F, G],
44 -
      F0: FunctorTell[F, L])
45 -
      : FunctorTell[G, L] =
44 +
      F0: FunctorTell[F, L]): FunctorTell[G, L] =
46 45
    new FunctorTellMonadPartialOrder[F, G, L] {
47 46
      val lift: MonadPartialOrder[F, G] = lift0
48 47
      val F: FunctorTell[F, L] = F0
49 48
    }
50 49
}
51 50
52 -
private[mtl] trait FunctorTellInstances extends LowPriorityFunctorTellInstances with LowPriorityFunctorTellInstancesCompat {
51 +
private[mtl] trait FunctorTellInstances
52 +
    extends LowPriorityFunctorTellInstances
53 +
    with LowPriorityFunctorTellInstancesCompat {
53 54
54 -
  implicit def functorTellForWriterT[F[_]: Applicative, L: Monoid]: FunctorTell[WriterT[F, L, *], L] =
55 +
  implicit def functorTellForWriterT[F[_]: Applicative, L: Monoid]
56 +
      : FunctorTell[WriterT[F, L, *], L] =
55 57
    new FunctorTell[WriterT[F, L, *], L] {
56 58
      val functor = Functor[WriterT[F, L, *]]
57 59
      def tell(l: L) = WriterT.tell[F, L](l)
@@ -64,9 +66,9 @@
Loading
64 66
65 67
  def tellF[F[_]]: tellFPartiallyApplied[F] = new tellFPartiallyApplied[F]
66 68
67 -
  final private[mtl] class tellFPartiallyApplied[F[_]](val dummy: Boolean = false) extends AnyVal {
68 -
    @inline def apply[L](l: L)(implicit tell: FunctorTell[F, L]): F[Unit] = {
69 +
  final private[mtl] class tellFPartiallyApplied[F[_]](val dummy: Boolean = false)
70 +
      extends AnyVal {
71 +
    @inline def apply[L](l: L)(implicit tell: FunctorTell[F, L]): F[Unit] =
69 72
      tell.tell(l)
70 -
    }
71 73
  }
72 74
}

@@ -15,22 +15,18 @@
Loading
15 15
  import cats.syntax.apply._
16 16
17 17
  // external laws:
18 -
  def askReflectsLocal(f: E => E): IsEq[F[E]] = {
18 +
  def askReflectsLocal(f: E => E): IsEq[F[E]] =
19 19
    local(f)(ask) <-> map(ask)(f)
20 -
  }
21 20
22 -
  def localPureIsPure[A](a: A, f: E => E): IsEq[F[A]] = {
21 +
  def localPureIsPure[A](a: A, f: E => E): IsEq[F[A]] =
23 22
    local(f)(pure(a)) <-> pure(a)
24 -
  }
25 23
26 -
  def localDistributesOverAp[A, B](fa: F[A], ff: F[A => B], f: E => E): IsEq[F[B]] = {
24 +
  def localDistributesOverAp[A, B](fa: F[A], ff: F[A => B], f: E => E): IsEq[F[B]] =
27 25
    local(f)(applicative.ap(ff)(fa)) <-> applicative.ap(local(f)(ff))(local(f)(fa))
28 -
  }
29 26
30 27
  // internal law:
31 -
  def scopeIsLocalConst[A](fa: F[A], e: E): IsEq[F[A]] = {
28 +
  def scopeIsLocalConst[A](fa: F[A], e: E): IsEq[F[A]] =
32 29
    scope(e)(fa) <-> local(_ => e)(fa)
33 -
  }
34 30
35 31
}
36 32

@@ -16,30 +16,26 @@
Loading
16 16
  import monad.pure
17 17
18 18
  // external laws:
19 -
  def getThenSetDoesNothing: IsEq[F[Unit]] = {
19 +
  def getThenSetDoesNothing: IsEq[F[Unit]] =
20 20
    (get >>= set) <-> pure(())
21 -
  }
22 21
23 -
  def setThenGetReturnsSetted(s: S): IsEq[F[S]] = {
22 +
  def setThenGetReturnsSetted(s: S): IsEq[F[S]] =
24 23
    (set(s) *> get) <-> (set(s) *> pure(s))
25 -
  }
26 24
27 -
  def setThenSetSetsLast(s1: S, s2: S): IsEq[F[Unit]] = {
25 +
  def setThenSetSetsLast(s1: S, s2: S): IsEq[F[Unit]] =
28 26
    set(s1) *> set(s2) <-> set(s2)
29 -
  }
30 27
31 -
  def getThenGetGetsOnce: IsEq[F[S]] = {
28 +
  def getThenGetGetsOnce: IsEq[F[S]] =
32 29
    get *> get <-> get
33 -
  }
34 30
35 31
  // internal law:
36 -
  def modifyIsGetThenSet(f: S => S): IsEq[F[Unit]] = {
32 +
  def modifyIsGetThenSet(f: S => S): IsEq[F[Unit]] =
37 33
    modify(f) <-> ((get map f) flatMap set)
38 -
  }
39 34
}
40 35
41 36
object MonadStateLaws {
42 -
  def apply[F[_], S](implicit instance0: MonadState[F, S]): MonadStateLaws[F, S] = new MonadStateLaws[F, S] {
43 -
    override lazy val stateInstance: MonadState[F, S] = instance0
44 -
  }
37 +
  def apply[F[_], S](implicit instance0: MonadState[F, S]): MonadStateLaws[F, S] =
38 +
    new MonadStateLaws[F, S] {
39 +
      override lazy val stateInstance: MonadState[F, S] = instance0
40 +
    }
45 41
}

@@ -11,8 +11,8 @@
Loading
11 11
  implicit val handleInstance: ApplicativeHandle[F, E]
12 12
  implicit val applicativeInstance: Applicative[F] = handleInstance.applicative
13 13
14 -
  import handleInstance.{handle, handleWith, attempt}
15 -
  import raiseInstance.{raise, catchNonFatal}
14 +
  import handleInstance.{attempt, handle, handleWith}
15 +
  import raiseInstance.{catchNonFatal, raise}
16 16
17 17
  import applicativeInstance._
18 18
@@ -37,16 +37,16 @@
Loading
37 37
38 38
  // internal laws:
39 39
  def catchNonFatalDefault[A](a: A, f: Throwable => E): IsEq[F[A]] =
40 -
    catchNonFatal(a)(f) <-> (try {
41 -
      pure(a)
42 -
    } catch {
40 +
    catchNonFatal(a)(f) <-> (try pure(a)
41 +
    catch {
43 42
      case NonFatal(ex) => raise(f(ex))
44 43
    })
45 44
46 45
}
47 46
48 47
object ApplicativeHandleLaws {
49 -
  def apply[F[_], E](implicit instance0: ApplicativeHandle[F, E]): ApplicativeHandleLaws[F, E] = {
48 +
  def apply[F[_], E](
49 +
      implicit instance0: ApplicativeHandle[F, E]): ApplicativeHandleLaws[F, E] = {
50 50
    new ApplicativeHandleLaws[F, E] {
51 51
      lazy val handleInstance: ApplicativeHandle[F, E] = instance0
52 52
      override lazy val raiseInstance: FunctorRaise[F, E] = instance0

@@ -14,18 +14,19 @@
Loading
14 14
15 15
  def laws: MonadChronicleLaws[F, E] = MonadChronicleLaws[F, E]
16 16
17 -
  def monadChronicle[A: Arbitrary](implicit ArbFA: Arbitrary[F[A]],
18 -
                                   ArbE: Arbitrary[E],
19 -
                                   CogenA: Cogen[A],
20 -
                                   CogenE: Cogen[E],
21 -
                                   EqFU: Eq[F[E]],
22 -
                                   EqFA: Eq[F[A]],
23 -
                                   EqFUnit: Eq[F[Unit]],
24 -
                                   EqFEIorUnit: Eq[F[E Ior Unit]],
25 -
                                   EqFEUnit: Eq[F[Either[E, Unit]]],
26 -
                                   EqFIor: Eq[F[E Ior A]],
27 -
                                   EqFEither: Eq[F[Either[E, A]]],
28 -
                                   SemigroupE: Semigroup[E]): RuleSet = {
17 +
  def monadChronicle[A: Arbitrary](
18 +
      implicit ArbFA: Arbitrary[F[A]],
19 +
      ArbE: Arbitrary[E],
20 +
      CogenA: Cogen[A],
21 +
      CogenE: Cogen[E],
22 +
      EqFU: Eq[F[E]],
23 +
      EqFA: Eq[F[A]],
24 +
      EqFUnit: Eq[F[Unit]],
25 +
      EqFEIorUnit: Eq[F[E Ior Unit]],
26 +
      EqFEUnit: Eq[F[Either[E, Unit]]],
27 +
      EqFIor: Eq[F[E Ior A]],
28 +
      EqFEither: Eq[F[Either[E, A]]],
29 +
      SemigroupE: Semigroup[E]): RuleSet = {
29 30
    new DefaultRuleSet(
30 31
      name = "monadChronicle",
31 32
      parent = None,
@@ -35,12 +36,15 @@
Loading
35 36
      "confess then retcon is confess" -> ∀(laws.confessThenRetconIsConfess[A] _),
36 37
      "dictate then condem is confess" -> ∀(laws.dictateThenCondemIsConfess[A] _),
37 38
      "dictate then materialize is both" -> ∀(laws.dictateThenMaterializeIsBoth _),
38 -
      "dictate then memento is dictate right unit" -> ∀(laws.dictateThenMementoIsDictateRightUnit _),
39 +
      "dictate then memento is dictate right unit" -> ∀(
40 +
        laws.dictateThenMementoIsDictateRightUnit _),
39 41
      "dictate then retcon is dictate" -> ∀(laws.dictateThenRetconIsDictate[A] _),
40 42
      "pure then materialize is right" -> ∀(laws.pureThenMaterializeIsRight[A] _),
41 43
      "pure then retcon is pure" -> ∀(laws.pureThenRetconIsPure[A] _),
42 -
      "dictate shark dictate is dictate semigroup" -> ∀(laws.dictateSharkDictateIsDictateSemigroup _),
43 -
      "dictate shark confess is confess semigroup" -> ∀(laws.dictateSharkConfessIsConfessSemigroup[A] _)
44 +
      "dictate shark dictate is dictate semigroup" -> ∀(
45 +
        laws.dictateSharkDictateIsDictateSemigroup _),
46 +
      "dictate shark confess is confess semigroup" -> ∀(
47 +
        laws.dictateSharkConfessIsConfessSemigroup[A] _)
44 48
    )
45 49
  }
46 50
}

@@ -12,17 +12,16 @@
Loading
12 12
13 13
  override def laws: ApplicativeLocalLaws[F, E] = ApplicativeLocalLaws[F, E]
14 14
15 -
  def applicativeLocal[A: Arbitrary, B](implicit
16 -
                                        ArbFA: Arbitrary[F[A]],
17 -
                                        ArbFAB: Arbitrary[F[A => B]],
18 -
                                        ArbEE: Arbitrary[E => E],
19 -
                                        ArbE: Arbitrary[E],
20 -
                                        CogenA: Cogen[A],
21 -
                                        CogenE: Cogen[E],
22 -
                                        EqFU: Eq[F[E]],
23 -
                                        EqFA: Eq[F[A]],
24 -
                                        EqFB: Eq[F[B]]
25 -
                                       ): RuleSet = {
15 +
  def applicativeLocal[A: Arbitrary, B](
16 +
      implicit ArbFA: Arbitrary[F[A]],
17 +
      ArbFAB: Arbitrary[F[A => B]],
18 +
      ArbEE: Arbitrary[E => E],
19 +
      ArbE: Arbitrary[E],
20 +
      CogenA: Cogen[A],
21 +
      CogenE: Cogen[E],
22 +
      EqFU: Eq[F[E]],
23 +
      EqFA: Eq[F[A]],
24 +
      EqFB: Eq[F[B]]): RuleSet = {
26 25
    new DefaultRuleSet(
27 26
      name = "applicativeLocal",
28 27
      parent = Some(applicativeAsk[A]),
@@ -36,7 +35,8 @@
Loading
36 35
}
37 36
38 37
object ApplicativeLocalTests {
39 -
  def apply[F[_], E](implicit instance0: ApplicativeLocal[F, E]): ApplicativeLocalTests[F, E] = {
38 +
  def apply[F[_], E](
39 +
      implicit instance0: ApplicativeLocal[F, E]): ApplicativeLocalTests[F, E] = {
40 40
    new ApplicativeLocalTests[F, E] {
41 41
      override lazy val localInstance: ApplicativeLocal[F, E] = instance0
42 42
      override lazy val askInstance: ApplicativeAsk[F, E] = instance0
Files Coverage
core/src/main/scala/cats/mtl 65.29%
laws/src/main/scala/cats/mtl/laws 90.67%
Project Totals (36 files) 72.71%
704.1
TRAVIS_JDK_VERSION=openjdk8
TRAVIS_OS_NAME=linux
704.2
TRAVIS_JDK_VERSION=openjdk8
TRAVIS_OS_NAME=linux
703.2
TRAVIS_JDK_VERSION=openjdk8
TRAVIS_OS_NAME=linux
703.1
TRAVIS_JDK_VERSION=openjdk8
TRAVIS_OS_NAME=linux

No yaml found.

Create your codecov.yml to customize your Codecov experience

Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.