Skip to content

Commit

Permalink
Merge pull request #2403 from typelevel/use-as-void
Browse files Browse the repository at this point in the history
use as and void instead of map(_ => )
  • Loading branch information
johnynek committed Aug 14, 2018
2 parents 578f140 + 851dca6 commit 30636cd
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion core/src/main/scala/cats/FlatMap.scala
Expand Up @@ -140,5 +140,5 @@ import simulacrum.noop
* }}}
*/
def flatTap[A, B](fa: F[A])(f: A => F[B]): F[A] =
flatMap(fa)(a => map(f(a))(_ => a))
flatMap(fa)(a => as(f(a), a))
}
2 changes: 1 addition & 1 deletion core/src/main/scala/cats/Functor.scala
Expand Up @@ -53,7 +53,7 @@ import simulacrum.typeclass
/**
* Empty the fa of the values, preserving the structure
*/
def void[A](fa: F[A]): F[Unit] = map(fa)(_ => ())
def void[A](fa: F[A]): F[Unit] = as(fa, ())

/**
* Tuple the values in fa with the result of applying a function
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/scala/cats/Reducible.scala
Expand Up @@ -127,7 +127,7 @@ import simulacrum.typeclass
* the traversal.
*/
def nonEmptyTraverse_[G[_], A, B](fa: F[A])(f: A => G[B])(implicit G: Apply[G]): G[Unit] =
G.map(reduceLeftTo(fa)(f)((x, y) => G.map2(x, f(y))((_, b) => b)))(_ => ())
G.void(reduceLeftTo(fa)(f)((x, y) => G.map2(x, f(y))((_, b) => b)))

/**
* Sequence `F[G[A]]` using `Apply[G]`.
Expand All @@ -137,7 +137,7 @@ import simulacrum.typeclass
* [[nonEmptyTraverse_]] documentation for a description of the differences.
*/
def nonEmptySequence_[G[_], A](fga: F[G[A]])(implicit G: Apply[G]): G[Unit] =
G.map(reduceLeft(fga)((x, y) => G.map2(x, y)((_, b) => b)))(_ => ())
G.void(reduceLeft(fga)((x, y) => G.map2(x, y)((_, b) => b)))

def toNonEmptyList[A](fa: F[A]): NonEmptyList[A] =
reduceRightTo(fa)(a => NonEmptyList(a, Nil)) { (a, lnel) =>
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/cats/data/Kleisli.scala
Expand Up @@ -69,7 +69,7 @@ final case class Kleisli[F[_], A, B](run: A => F[B]) { self =>

/** Discard computed B and yield the input value. */
def tap(implicit F: Functor[F]): Kleisli[F, A, A] =
Kleisli(a => F.map(run(a))(_ => a))
Kleisli(a => F.as(run(a), a))

/** Yield computed B combined with input value. */
def tapWith[C](f: (A, B) => C)(implicit F: Functor[F]): Kleisli[F, A, C] =
Expand Down

0 comments on commit 30636cd

Please sign in to comment.