Skip to content

Commit

Permalink
Scalafmt
Browse files Browse the repository at this point in the history
  • Loading branch information
LukaJCB committed Sep 20, 2019
1 parent 2523014 commit 909a33a
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 56 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Expand Up @@ -398,7 +398,7 @@ def mimaSettings(moduleName: String) =
exclude[MissingClassProblem](
"cats.kernel.compat.scalaVersionMoreSpecific$suppressUnusedImportWarningForScalaVersionMoreSpecific"
)
) ++ //abstract package private classes
) ++ //abstract package private classes
Seq(
exclude[DirectMissingMethodProblem]("cats.data.AbstractNonEmptyInstances.this")
)
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala-2.12/cats/compat/Vector.scala
Expand Up @@ -3,4 +3,4 @@ package cats.compat
private[cats] object Vector {
def zipWith[A, B, C](fa: Vector[A], fb: Vector[B])(f: (A, B) => C): Vector[C] =
(fa, fb).zipped.map(f)
}
}
64 changes: 32 additions & 32 deletions core/src/main/scala/cats/data/NonEmptyChain.scala
Expand Up @@ -422,38 +422,38 @@ sealed abstract private[data] class NonEmptyChainInstances extends NonEmptyChain
with NonEmptyTraverse[NonEmptyChain]
with Bimonad[NonEmptyChain]
with Align[NonEmptyChain] =
new AbstractNonEmptyInstances[Chain, NonEmptyChain] {
def extract[A](fa: NonEmptyChain[A]): A = fa.head

def nonEmptyTraverse[G[_]: Apply, A, B](fa: NonEmptyChain[A])(f: A => G[B]): G[NonEmptyChain[B]] =
Foldable[Chain]
.reduceRightToOption[A, G[Chain[B]]](fa.tail)(a => Apply[G].map(f(a))(Chain.one)) { (a, lglb) =>
Apply[G].map2Eval(f(a), lglb)(_ +: _)
}
.map {
case None => Apply[G].map(f(fa.head))(NonEmptyChain.one)
case Some(gtail) => Apply[G].map2(f(fa.head), gtail)((h, t) => create(Chain.one(h) ++ t))
}
.value

override def size[A](fa: NonEmptyChain[A]): Long = fa.length

override def reduceLeft[A](fa: NonEmptyChain[A])(f: (A, A) => A): A =
fa.reduceLeft(f)

override def reduce[A](fa: NonEmptyChain[A])(implicit A: Semigroup[A]): A =
fa.reduce

def reduceLeftTo[A, B](fa: NonEmptyChain[A])(f: A => B)(g: (B, A) => B): B = fa.reduceLeftTo(f)(g)

def reduceRightTo[A, B](fa: NonEmptyChain[A])(f: A => B)(g: (A, cats.Eval[B]) => cats.Eval[B]): cats.Eval[B] =
Eval.defer(fa.reduceRightTo(a => Eval.now(f(a))) { (a, b) =>
Eval.defer(g(a, b))
})

override def get[A](fa: NonEmptyChain[A])(idx: Long): Option[A] =
if (idx == 0) Some(fa.head) else fa.tail.get(idx - 1)
}
new AbstractNonEmptyInstances[Chain, NonEmptyChain] {
def extract[A](fa: NonEmptyChain[A]): A = fa.head

def nonEmptyTraverse[G[_]: Apply, A, B](fa: NonEmptyChain[A])(f: A => G[B]): G[NonEmptyChain[B]] =
Foldable[Chain]
.reduceRightToOption[A, G[Chain[B]]](fa.tail)(a => Apply[G].map(f(a))(Chain.one)) { (a, lglb) =>
Apply[G].map2Eval(f(a), lglb)(_ +: _)
}
.map {
case None => Apply[G].map(f(fa.head))(NonEmptyChain.one)
case Some(gtail) => Apply[G].map2(f(fa.head), gtail)((h, t) => create(Chain.one(h) ++ t))
}
.value

override def size[A](fa: NonEmptyChain[A]): Long = fa.length

override def reduceLeft[A](fa: NonEmptyChain[A])(f: (A, A) => A): A =
fa.reduceLeft(f)

override def reduce[A](fa: NonEmptyChain[A])(implicit A: Semigroup[A]): A =
fa.reduce

def reduceLeftTo[A, B](fa: NonEmptyChain[A])(f: A => B)(g: (B, A) => B): B = fa.reduceLeftTo(f)(g)

def reduceRightTo[A, B](fa: NonEmptyChain[A])(f: A => B)(g: (A, cats.Eval[B]) => cats.Eval[B]): cats.Eval[B] =
Eval.defer(fa.reduceRightTo(a => Eval.now(f(a))) { (a, b) =>
Eval.defer(g(a, b))
})

override def get[A](fa: NonEmptyChain[A])(idx: Long): Option[A] =
if (idx == 0) Some(fa.head) else fa.tail.get(idx - 1)
}

implicit def catsDataOrderForNonEmptyChain[A: Order]: Order[NonEmptyChain[A]] =
Order[Chain[A]].asInstanceOf[Order[NonEmptyChain[A]]]
Expand Down
24 changes: 13 additions & 11 deletions laws/src/main/scala/cats/laws/AlignLaws.scala
Expand Up @@ -5,7 +5,7 @@ import cats.syntax.align._
import cats.syntax.functor._

import cats.data.Ior
import cats.data.Ior.{Left, Right, Both}
import cats.data.Ior.{Both, Left, Right}

/**
* Laws that must be obeyed by any `Align`.
Expand All @@ -29,16 +29,18 @@ trait AlignLaws[F[_]] {

private def assoc[A, B, C](x: Ior[A, Ior[B, C]]): Ior[Ior[A, B], C] = x match {
case Left(a) => Left(Left(a))
case Right(bc) => bc match {
case Left(b) => Left(Right(b))
case Right(c) => Right(c)
case Both(b, c) => Both(Right(b), c)
}
case Both(a, bc) => bc match {
case Left(b) => Left(Both(a, b))
case Right(c) => Both(Left(a), c)
case Both(b, c) => Both(Both(a, b), c)
}
case Right(bc) =>
bc match {
case Left(b) => Left(Right(b))
case Right(c) => Right(c)
case Both(b, c) => Both(Right(b), c)
}
case Both(a, bc) =>
bc match {
case Left(b) => Left(Both(a, b))
case Right(c) => Both(Left(a), c)
case Both(b, c) => Both(Both(a, b), c)
}
}
}

Expand Down
22 changes: 11 additions & 11 deletions laws/src/main/scala/cats/laws/discipline/AlignTests.scala
Expand Up @@ -28,17 +28,17 @@ trait AlignTests[F[_]] extends Laws {
EqFIorAB: Eq[F[A Ior B]],
EqFIorCD: Eq[F[C Ior D]],
EqFAssoc: Eq[F[Ior[Ior[A, B], C]]]
): RuleSet = new DefaultRuleSet(
name = "align",
parent = None,
"align associativity" -> forAll(laws.alignAssociativity[A, B, C] _),
"align self both" -> forAll(laws.alignSelfBoth[A] _),
"align homomorphism" -> forAll { (fa: F[A], fb: F[B], f: A => C, g: B => D) =>
laws.alignHomomorphism[A, B, C, D](fa, fb, f, g)
},
"alignWith consistent" -> forAll { (fa: F[A], fb: F[B], f: A Ior B => C) =>
laws.alignWithConsistent[A, B, C](fa, fb, f)
})
): RuleSet =
new DefaultRuleSet(name = "align",
parent = None,
"align associativity" -> forAll(laws.alignAssociativity[A, B, C] _),
"align self both" -> forAll(laws.alignSelfBoth[A] _),
"align homomorphism" -> forAll { (fa: F[A], fb: F[B], f: A => C, g: B => D) =>
laws.alignHomomorphism[A, B, C, D](fa, fb, f, g)
},
"alignWith consistent" -> forAll { (fa: F[A], fb: F[B], f: A Ior B => C) =>
laws.alignWithConsistent[A, B, C](fa, fb, f)
})
}

object AlignTests {
Expand Down

0 comments on commit 909a33a

Please sign in to comment.