Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use as and void instead of map(_ => ) #2403

Merged
merged 1 commit into from
Aug 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/src/main/scala/cats/FlatMap.scala
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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