Skip to content

Commit

Permalink
Fix a few more instances
Browse files Browse the repository at this point in the history
  • Loading branch information
travisbrown committed Dec 4, 2019
1 parent 0b415ed commit d6721d6
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions core/src/main/scala-2.13+/cats/instances/lazyList.scala
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,9 @@ trait LazyListInstances extends cats.kernel.instances.LazyListInstances {
def applicative: Applicative[ZipLazyList] = ZipLazyList.catsDataAlternativeForZipLazyList

def sequential: ZipLazyList ~> LazyList =
new (ZipLazyList ~> LazyList) { def apply[A](a: ZipLazyList[A]): LazyList[A] = a.value }
new (ZipLazyList ~> LazyList) { def apply[B](zll: ZipLazyList[B]): LazyList[B] = zll.value }

def parallel: LazyList ~> ZipLazyList =
new (LazyList ~> ZipLazyList) { def apply[A](v: LazyList[A]): ZipLazyList[A] = new ZipLazyList(v) }
new (LazyList ~> ZipLazyList) { def apply[B](ll: LazyList[B]): ZipLazyList[B] = new ZipLazyList(ll) }
}
}
6 changes: 3 additions & 3 deletions free/src/main/scala/cats/free/Free.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ sealed abstract class Free[S[_], A] extends Product with Serializable {
*/
final def mapK[T[_]](f: S ~> T): Free[T, A] =
foldMap[Free[T, *]] { // this is safe because Free is stack safe
new FunctionK[S, Free[T, *]] { def apply[A](fa: S[A]): Free[T, A] = Suspend(f(fa)) }
new FunctionK[S, Free[T, *]] { def apply[B](sb: S[B]): Free[T, B] = Suspend(f(sb)) }
}

/**
Expand Down Expand Up @@ -181,10 +181,10 @@ sealed abstract class Free[S[_], A] extends Product with Serializable {
*}}}
*/
final def inject[G[_]](implicit ev: InjectK[S, G]): Free[G, A] =
mapK(new (S ~> G) { def apply[A](a: S[A]): G[A] = ev.inj(a) })
mapK(new (S ~> G) { def apply[B](sb: S[B]): G[B] = ev.inj(sb) })

final def toFreeT[G[_]: Applicative]: FreeT[S, G, A] =
foldMap[FreeT[S, G, *]](new (S ~> FreeT[S, G, *]) { def apply[A](a: S[A]): FreeT[S, G, A] = FreeT.liftF(a) })
foldMap[FreeT[S, G, *]](new (S ~> FreeT[S, G, *]) { def apply[B](sb: S[B]): FreeT[S, G, B] = FreeT.liftF(sb) })

override def toString: String =
"Free(...)"
Expand Down
6 changes: 3 additions & 3 deletions free/src/main/scala/cats/free/FreeApplicative.scala
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ sealed abstract class FreeApplicative[F[_], A] extends Product with Serializable
*/
final def compile[G[_]](f: F ~> G): FA[G, A] =
foldMap[FA[G, *]] {
new FunctionK[F, FA[G, *]] { def apply[A](fa: F[A]): FA[G, A] = lift(f(fa)) }
new FunctionK[F, FA[G, *]] { def apply[B](fb: F[B]): FA[G, B] = lift(f(fb)) }
}

/**
Expand All @@ -154,13 +154,13 @@ sealed abstract class FreeApplicative[F[_], A] extends Product with Serializable
/** Interpret this algebra into a Monoid. */
final def analyze[M: Monoid](f: FunctionK[F, λ[α => M]]): M =
foldMap[Const[M, *]](
new FunctionK[F, Const[M, *]] { def apply[A](x: F[A]): Const[M, A] = Const(f(x)) }
new FunctionK[F, Const[M, *]] { def apply[B](fb: F[B]): Const[M, B] = Const(f(fb)) }
).getConst

/** Compile this FreeApplicative algebra into a Free algebra. */
final def monad: Free[F, A] =
foldMap[Free[F, *]] {
new FunctionK[F, Free[F, *]] { def apply[A](fa: F[A]): Free[F, A] = Free.liftF(fa) }
new FunctionK[F, Free[F, *]] { def apply[B](fb: F[B]): Free[F, B] = Free.liftF(fb) }
}

override def toString: String = "FreeApplicative(...)"
Expand Down
4 changes: 2 additions & 2 deletions free/src/main/scala/cats/free/FreeInvariantMonoidal.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ sealed abstract class FreeInvariantMonoidal[F[_], A] extends Product with Serial
/** Interpret this algebra into another InvariantMonoidal */
final def compile[G[_]](f: FunctionK[F, G]): FA[G, A] =
foldMap[FA[G, *]] {
new FunctionK[F, FA[G, *]] { def apply[A](fa: F[A]): FA[G, A] = lift(f(fa)) }
new FunctionK[F, FA[G, *]] { def apply[B](fb: F[B]): FA[G, B] = lift(f(fb)) }
}

/** Interpret this algebra into a Monoid */
final def analyze[M: Monoid](f: FunctionK[F, λ[α => M]]): M =
foldMap[Const[M, *]](
new FunctionK[F, Const[M, *]] { def apply[A](x: F[A]): Const[M, A] = Const(f(x)) }
new FunctionK[F, Const[M, *]] { def apply[B](fb: F[B]): Const[M, B] = Const(f(fb)) }
).getConst
}

Expand Down

0 comments on commit d6721d6

Please sign in to comment.