Skip to content

Commit

Permalink
Format
Browse files Browse the repository at this point in the history
  • Loading branch information
travisbrown committed Jun 18, 2020
1 parent 9cbbff3 commit 0dc267c
Show file tree
Hide file tree
Showing 65 changed files with 342 additions and 219 deletions.
5 changes: 2 additions & 3 deletions core/src/main/scala-2.12/cats/compat/FoldableCompat.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ private[cats] object FoldableCompat {

def toIterable[F[_], A](fa: F[A])(F: Foldable[F]): Iterable[A] =
F.foldRight[A, Stream[A]](fa, Eval.now(Stream.empty)) { (a, eb) =>
eb.map(Stream.cons(a, _))
}
.value
eb.map(Stream.cons(a, _))
}.value
}
5 changes: 2 additions & 3 deletions core/src/main/scala-2.13+/cats/compat/FoldableCompat.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ private[cats] object FoldableCompat {

def toIterable[F[_], A](fa: F[A])(F: Foldable[F]): Iterable[A] =
F.foldRight[A, LazyList[A]](fa, Eval.now(LazyList.empty)) { (a, eb) =>
eb.map(LazyList.cons(a, _))
}
.value
eb.map(LazyList.cons(a, _))
}.value
}
13 changes: 6 additions & 7 deletions core/src/main/scala-2.13+/cats/data/NonEmptyLazyList.scala
Original file line number Diff line number Diff line change
Expand Up @@ -418,44 +418,43 @@ class NonEmptyLazyListOps[A](private val value: NonEmptyLazyList[A])

/**
* Creates new `NonEmptyMap`, similarly to List#toMap from scala standard library.
*{{{
* {{{
* scala> import cats.data.{NonEmptyLazyList, NonEmptyMap}
* scala> import cats.implicits._
* scala> val nel = NonEmptyLazyList.fromLazyListPrepend((0, "a"), LazyList((1, "b"),(0, "c"), (2, "d")))
* scala> val expectedResult = NonEmptyMap.of(0 -> "c", 1 -> "b", 2 -> "d")
* scala> val result = nel.toNem
* scala> result === expectedResult
* res0: Boolean = true
*}}}
*
* }}}
*/
final def toNem[T, U](implicit ev: A <:< (T, U), order: Order[T]): NonEmptyMap[T, U] =
NonEmptyMap.fromMapUnsafe(SortedMap(toLazyList.map(ev): _*)(order.toOrdering))

/**
* Creates new `NonEmptySet`, similarly to List#toSet from scala standard library.
*{{{
* {{{
* scala> import cats.data._
* scala> import cats.instances.int._
* scala> val nel = NonEmptyLazyList.fromLazyListPrepend(1, LazyList(2,2,3,4))
* scala> nel.toNes
* res0: cats.data.NonEmptySet[Int] = TreeSet(1, 2, 3, 4)
*}}}
* }}}
*/
final def toNes[B >: A](implicit order: Order[B]): NonEmptySet[B] =
NonEmptySet.of(head, tail: _*)

/**
* Creates new `NonEmptyVector`, similarly to List#toVector from scala standard library.
*{{{
* {{{
* scala> import cats.data._
* scala> import cats.instances.int._
* scala> val nel = NonEmptyLazyList.fromLazyListPrepend(1, LazyList(2,3,4))
* scala> val expectedResult = NonEmptyVector.fromVectorUnsafe(Vector(1,2,3,4))
* scala> val result = nel.toNev
* scala> result === expectedResult
* res0: Boolean = true
*}}}
* }}}
*/
final def toNev[B >: A]: NonEmptyVector[B] =
NonEmptyVector.fromVectorUnsafe(toLazyList.toVector)
Expand Down
14 changes: 6 additions & 8 deletions core/src/main/scala-2.13+/cats/instances/arraySeq.scala
Original file line number Diff line number Diff line change
Expand Up @@ -192,16 +192,14 @@ private[cats] object ArraySeqInstances {
fa: ArraySeq[A]
)(f: (A) => G[Option[B]])(implicit G: Applicative[G]): G[ArraySeq[B]] =
fa.foldRight(Eval.now(G.pure(ArraySeq.untagged.empty[B]))) {
case (x, xse) =>
G.map2Eval(f(x), xse)((i, o) => i.fold(o)(_ +: o))
}
.value
case (x, xse) =>
G.map2Eval(f(x), xse)((i, o) => i.fold(o)(_ +: o))
}.value

override def filterA[G[_], A](fa: ArraySeq[A])(f: (A) => G[Boolean])(implicit G: Applicative[G]): G[ArraySeq[A]] =
fa.foldRight(Eval.now(G.pure(ArraySeq.untagged.empty[A]))) {
case (x, xse) =>
G.map2Eval(f(x), xse)((b, vec) => if (b) x +: vec else vec)
}
.value
case (x, xse) =>
G.map2Eval(f(x), xse)((b, vec) => if (b) x +: vec else vec)
}.value
}
}
2 changes: 1 addition & 1 deletion core/src/main/scala/cats/ApplicativeError.scala
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ trait ApplicativeError[F[_], E] extends Applicative[F] {
* scala> val prog2: F[Int] = (Err("two")).raiseError[F, Int]
*
* scala> prog1.onError(action).value.run("").value
*
* res0: (String, Either[Err,Int]) = (one,Left(Err(one)))
*
* scala> prog2.onError(action).value.run("").value
Expand Down
16 changes: 10 additions & 6 deletions core/src/main/scala/cats/Apply.scala
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ trait Apply[F[_]] extends Functor[F] with InvariantSemigroupal[F] with ApplyArit
* scala> Apply[ErrOr].productR(invalidInt)(invalidBool)
* res3: ErrOr[Boolean] = Invalid(Invalid int.Invalid boolean.)
* }}}
*
*/
def productR[A, B](fa: F[A])(fb: F[B]): F[B] =
ap(map(fa)(_ => (b: B) => b))(fb)
Expand Down Expand Up @@ -113,24 +112,29 @@ trait Apply[F[_]] extends Functor[F] with InvariantSemigroupal[F] with ApplyArit
override def product[A, B](fa: F[A], fb: F[B]): F[(A, B)] =
ap(map(fa)(a => (b: B) => (a, b)))(fb)

/** Alias for [[ap]]. */
/**
* Alias for [[ap]]. */
@inline final def <*>[A, B](ff: F[A => B])(fa: F[A]): F[B] =
ap(ff)(fa)

/** Alias for [[productR]]. */
/**
* Alias for [[productR]]. */
@inline final def *>[A, B](fa: F[A])(fb: F[B]): F[B] =
productR(fa)(fb)

/** Alias for [[productL]]. */
/**
* Alias for [[productL]]. */
@inline final def <*[A, B](fa: F[A])(fb: F[B]): F[A] =
productL(fa)(fb)

/** Alias for [[productR]]. */
/**
* Alias for [[productR]]. */
@deprecated("Use *> or productR instead.", "1.0.0-RC2")
@noop @inline final private[cats] def followedBy[A, B](fa: F[A])(fb: F[B]): F[B] =
productR(fa)(fb)

/** Alias for [[productL]]. */
/**
* Alias for [[productL]]. */
@deprecated("Use <* or productL instead.", "1.0.0-RC2")
@noop @inline final private[cats] def forEffect[A, B](fa: F[A])(fb: F[B]): F[A] =
productL(fa)(fb)
Expand Down
9 changes: 6 additions & 3 deletions core/src/main/scala/cats/Bifoldable.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@ import scala.annotation.implicitNotFound
@implicitNotFound("Could not find an instance of Bifoldable for ${F}")
@typeclass trait Bifoldable[F[_, _]] extends Serializable { self =>

/** Collapse the structure with a left-associative function */
/**
* Collapse the structure with a left-associative function */
def bifoldLeft[A, B, C](fab: F[A, B], c: C)(f: (C, A) => C, g: (C, B) => C): C

/** Collapse the structure with a right-associative function */
/**
* Collapse the structure with a right-associative function */
def bifoldRight[A, B, C](fab: F[A, B], c: Eval[C])(f: (A, Eval[C]) => Eval[C], g: (B, Eval[C]) => Eval[C]): Eval[C]

/** Collapse the structure by mapping each element to an element of a type that has a [[cats.Monoid]] */
/**
* Collapse the structure by mapping each element to an element of a type that has a [[cats.Monoid]] */
def bifoldMap[A, B, C](fab: F[A, B])(f: A => C, g: B => C)(implicit C: Monoid[C]): C =
bifoldLeft(fab, C.empty)(
(c: C, a: A) => C.combine(c, f(a)),
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/scala/cats/Bifunctor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ import scala.annotation.implicitNotFound
*/
def leftMap[A, B, C](fab: F[A, B])(f: A => C): F[C, B] = bimap(fab)(f, identity)

/** The composition of two Bifunctors is itself a Bifunctor */
/**
* The composition of two Bifunctors is itself a Bifunctor */
def compose[G[_, _]](implicit G0: Bifunctor[G]): Bifunctor[λ[(α, β) => F[G[α, β], G[α, β]]]] =
new ComposedBifunctor[F, G] {
val F = self
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/scala/cats/Bitraverse.scala
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ import scala.annotation.implicitNotFound
def bisequence[G[_]: Applicative, A, B](fab: F[G[A], G[B]]): G[F[A, B]] =
bitraverse(fab)(identity, identity)

/** If F and G are both [[cats.Bitraverse]] then so is their composition F[G[_, _], G[_, _]] */
/**
* If F and G are both [[cats.Bitraverse]] then so is their composition F[G[_, _], G[_, _]] */
def compose[G[_, _]](implicit ev: Bitraverse[G]): Bitraverse[λ[(α, β) => F[G[α, β], G[α, β]]]] =
new ComposedBitraverse[F, G] {
val F = self
Expand Down
10 changes: 5 additions & 5 deletions core/src/main/scala/cats/Foldable.scala
Original file line number Diff line number Diff line change
Expand Up @@ -311,26 +311,26 @@ import scala.annotation.implicitNotFound

/**
* Tear down a subset of this structure using a `PartialFunction`.
*{{{
* {{{
* scala> import cats.implicits._
* scala> val xs = List(1, 2, 3, 4)
* scala> Foldable[List].collectFold(xs) { case n if n % 2 == 0 => n }
* res0: Int = 6
*}}}
* }}}
*/
@noop
def collectFold[A, B](fa: F[A])(f: PartialFunction[A, B])(implicit B: Monoid[B]): B =
foldLeft(fa, B.empty)((acc, a) => B.combine(acc, f.applyOrElse(a, (_: A) => B.empty)))

/**
* Tear down a subset of this structure using a `A => Option[M]`.
*{{{
* {{{
* scala> import cats.implicits._
* scala> val xs = List(1, 2, 3, 4)
* scala> def f(n: Int): Option[Int] = if (n % 2 == 0) Some(n) else None
* scala> Foldable[List].collectFoldSome(xs)(f)
* res0: Int = 6
*}}}
* }}}
*/
def collectFoldSome[A, B](fa: F[A])(f: A => Option[B])(implicit B: Monoid[B]): B =
foldLeft(fa, B.empty)((acc, a) =>
Expand Down Expand Up @@ -424,7 +424,7 @@ import scala.annotation.implicitNotFound
* scala> val a = x("foo")
* a: String = "foo321"
* }}}
* */
*/
@noop
def foldMapK[G[_], A, B](fa: F[A])(f: A => G[B])(implicit G: MonoidK[G]): G[B] =
foldRight(fa, Eval.now(G.empty[B])) { (a, evalGb) =>
Expand Down
1 change: 0 additions & 1 deletion core/src/main/scala/cats/Functor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ import scala.annotation.implicitNotFound
* scala> Functor[List].unzip(List((1,2), (3, 4)))
* res0: (List[Int], List[Int]) = (List(1, 3),List(2, 4))
* }}}
*
*/
@noop
def unzip[A, B](fab: F[(A, B)]): (F[A], F[B]) = (map(fab)(_._1), map(fab)(_._2))
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/cats/Reducible.scala
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ import scala.annotation.implicitNotFound
* scala> val a = x("foo")
* a: String = "foo321"
* }}}
* */
*/
@noop
def reduceMapK[G[_], A, B](fa: F[A])(f: A => G[B])(implicit G: SemigroupK[G]): G[B] =
reduceLeftTo(fa)(f)((b, a) => G.combineK(b, f(a)))
Expand Down
6 changes: 4 additions & 2 deletions core/src/main/scala/cats/Show.scala
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,15 @@ object Show extends ScalaVersionSpecificShowInstances with ShowInstances {
}
}

/** creates an instance of [[Show]] using the provided function */
/**
* creates an instance of [[Show]] using the provided function */
def show[A](f: A => String): Show[A] =
new Show[A] {
def show(a: A): String = f(a)
}

/** creates an instance of [[Show]] using object toString */
/**
* creates an instance of [[Show]] using object toString */
def fromToString[A]: Show[A] =
new Show[A] {
def show(a: A): String = a.toString
Expand Down
3 changes: 1 addition & 2 deletions core/src/main/scala/cats/TraverseFilter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,12 @@ trait TraverseFilter[F[_]] extends FunctorFilter[F] {
* scala> val b: Either[String, List[Int]] = TraverseFilter[List].sequenceFilter(a)
* b: Either[String, List[Int]] = Right(List(1, 5, 3))
* }}}
* */
*/
@noop
def sequenceFilter[G[_], A](fgoa: F[G[Option[A]]])(implicit G: Applicative[G]): G[F[A]] =
traverseFilter(fgoa)(identity)

/**
*
* Filter values inside a `G` context.
*
* This is a generalized version of Haskell's [[http://hackage.haskell.org/package/base-4.9.0.0/docs/Control-Monad.html#v:filterM filterM]].
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/scala/cats/data/AndThen.scala
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ sealed abstract class AndThen[-T, +R] extends (T => R) with Product with Seriali

object AndThen extends AndThenInstances0 {

/** Builds an [[AndThen]] reference by wrapping a plain function. */
/**
* Builds an [[AndThen]] reference by wrapping a plain function. */
def apply[A, B](f: A => B): AndThen[A, B] =
f match {
case ref: AndThen[A, B] @unchecked => ref
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/scala/cats/data/Binested.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ package data

import cats.arrow._

/** Compose a two-slot type constructor `F[_, _]` with two single-slot type constructors
/**
* Compose a two-slot type constructor `F[_, _]` with two single-slot type constructors
* `G[_]` and `H[_]`, resulting in a two-slot type constructor with respect to the inner types.
* For example, `List` and `Option` both have `Functor` instances, and `Either` has a
* `Bifunctor` instance. Therefore, `Binested[Either, List, Option, *, *]` has a `Bifunctor`
Expand Down
15 changes: 10 additions & 5 deletions core/src/main/scala/cats/data/Chain.scala
Original file line number Diff line number Diff line change
Expand Up @@ -595,27 +595,32 @@ object Chain extends ChainInstances {
c.initLast
}

/** Empty Chain. */
/**
* Empty Chain. */
val nil: Chain[Nothing] = Empty

def empty[A]: Chain[A] = nil

/** Creates a Chain of 1 element. */
/**
* Creates a Chain of 1 element. */
def one[A](a: A): Chain[A] = Singleton(a)

/** Concatenates two Chains. */
/**
* Concatenates two Chains. */
def concat[A](c: Chain[A], c2: Chain[A]): Chain[A] =
if (c.isEmpty) c2
else if (c2.isEmpty) c
else Append(c, c2)

/** Creates a Chain from the specified sequence. */
/**
* Creates a Chain from the specified sequence. */
def fromSeq[A](s: Seq[A]): Chain[A] =
if (s.isEmpty) nil
else if (s.lengthCompare(1) == 0) one(s.head)
else Wrap(s)

/** Creates a Chain from the specified elements. */
/**
* Creates a Chain from the specified elements. */
def apply[A](as: A*): Chain[A] =
fromSeq(as)

Expand Down
6 changes: 4 additions & 2 deletions core/src/main/scala/cats/data/ContT.scala
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ object ContT {
lazy val runAndThen: AndThen[B => M[A], M[A]] = loop(next).runAndThen
}

/** Lift a pure value into `ContT` */
/**
* Lift a pure value into `ContT` */
def pure[M[_], A, B](b: B): ContT[M, A, B] =
apply { cb =>
cb(b)
Expand Down Expand Up @@ -152,7 +153,8 @@ object ContT {
def apply[M[_], A, B](fn: (B => M[A]) => M[A]): ContT[M, A, B] =
FromFn(AndThen(fn))

/** Similar to [[apply]] but evaluation of the argument is deferred. */
/**
* Similar to [[apply]] but evaluation of the argument is deferred. */
def later[M[_], A, B](fn: => (B => M[A]) => M[A]): ContT[M, A, B] =
DeferCont(() => FromFn(AndThen(fn)))

Expand Down
3 changes: 2 additions & 1 deletion core/src/main/scala/cats/data/EitherK.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ package data
import cats.Contravariant
import cats.arrow.FunctionK

/** `F` on the left and `G` on the right of `scala.util.Either`.
/**
* `F` on the left and `G` on the right of `scala.util.Either`.
*
* @param run The underlying `scala.util.Either`.
*/
Expand Down
Loading

0 comments on commit 0dc267c

Please sign in to comment.