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

Deprecate FlatMap's >> and << #1955

Merged
merged 4 commits into from
Oct 10, 2017

Conversation

LukaJCB
Copy link
Member

@LukaJCB LukaJCB commented Oct 7, 2017

To do so, I moved *> and <* from Cartesian syntax to Cartesian type class. I also moved followedBy and forEffect to Apply. :)

Should fix #1954

@codecov-io
Copy link

codecov-io commented Oct 7, 2017

Codecov Report

Merging #1955 into master will decrease coverage by 0.04%.
The diff coverage is 55.55%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1955      +/-   ##
==========================================
- Coverage   96.14%   96.09%   -0.05%     
==========================================
  Files         273      273              
  Lines        4535     4536       +1     
  Branches      117      132      +15     
==========================================
- Hits         4360     4359       -1     
- Misses        175      177       +2
Impacted Files Coverage Δ
laws/src/main/scala/cats/laws/FlatMapLaws.scala 100% <ø> (ø) ⬆️
core/src/main/scala/cats/syntax/cartesian.scala 50% <ø> (ø) ⬆️
core/src/main/scala/cats/FlatMap.scala 100% <ø> (+7.69%) ⬆️
core/src/main/scala/cats/syntax/flatMap.scala 66.66% <0%> (-33.34%) ⬇️
laws/src/main/scala/cats/laws/ApplyLaws.scala 100% <100%> (ø) ⬆️
core/src/main/scala/cats/Apply.scala 84.61% <75%> (-4.28%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 29faf62...95ac1ab. Read the comment docs.

@@ -19,6 +19,14 @@ trait Apply[F[_]] extends Functor[F] with Cartesian[F] with ApplyArityFunctions[
override def product[A, B](fa: F[A], fb: F[B]): F[(A, B)] =
ap(map(fa)(a => (b: B) => (a, b)))(fb)

/** Sequentially compose two actions, discarding any value produced by the first. */
def followedBy[A, B](fa: F[A])(fb: F[B]): F[B] =
map(product(fa, fb)) { case (_, b) => b }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn’t we use map2 here since that can sometimes be more efficient than product + map

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that's a great idea

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also I think "sequentially" is confusing now. It is sequential if we have a monad, if we have an applicative it is not necessarily "sequential"

@@ -14,6 +14,12 @@ import simulacrum.typeclass
*/
@typeclass trait Cartesian[F[_]] {
def product[A, B](fa: F[A], fb: F[B]): F[(A, B)]

@inline final def *>[A, B](fa: F[A])(fb: F[B])(implicit F: Functor[F]): F[B] =
F.map(product(fa, fb)) { case (_, b) => b }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don’t like this. If you have a Functor for Cartesian you have an Apply, no?

I’m -1 in accepting other type classes on F in methods for a typeclass of F in most cases.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I don’t see why these aren’t exactly symbols for the methods you moved to Apply.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add these as aliases for those in apply :)

@@ -17,10 +17,4 @@ abstract class CartesianOps[F[_], A] extends Cartesian.Ops[F, A] {
final def |@|[B](fb: F[B]): CartesianBuilder[F]#CartesianBuilder2[A, B] =
new CartesianBuilder[F] |@| self |@| fb

final def *>[B](fb: F[B])(implicit F: Functor[F]): F[B] =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh. I see someone put them here originally. This was an error in my view. They should be on Apply.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah +1 on that :)

@@ -215,8 +215,6 @@ All other symbols can be imported with `import cats.implicits._`
| `x === y` | equals | | `Eq[A]` | `eqv(x: A, y: A): Boolean` |
| `x =!= y` | not equals | | `Eq[A]` | `neqv(x: A, y: A): Boolean` |
| `fa >>= f` | flatMap | | `FlatMap[F[_]]` | `flatMap(fa: F[A])(f: A => F[B]): F[B]` |
| `fa >> fb` | followed by | | `FlatMap[F[_]]` | `followedBy(fa: F[A])(fb: F[B]): F[B]` |
| `fa << fb` | for effect | | `FlatMap[F[_]]` | `forEffect(fa: F[A])(fb: F[B]): F[A]` |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we not add them back to another place place in the doc?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added them at the bottom with a deprecated notice

@@ -189,7 +189,7 @@ class FreeTests extends CatsSuite {
forAll { (x: Int, y: Int) =>
val expr1: Free[T, Int] = Free.injectRoll[T, Test1Algebra, Int](Test1(x, Free.pure))
val expr2: Free[T, Int] = Free.injectRoll[T, Test2Algebra, Int](Test2(y, Free.pure))
val res = distr[T, Int](expr1 >> expr2)
val res = distr[T, Int](expr1 >>= (_ => expr2))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why won’t *> work here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was something odd going on with the tests so that simply replacing >> with *> did not work.

@johnynek
Copy link
Contributor

johnynek commented Oct 8, 2017

Looks good to me except for coverage. I’m on the phone now but can we exercise each of the lines to make sure there isn’t any issue that we don’t notice?

Also, I wonder if this is really the last example where we have methods on the wrong type classes. Hard to catch except by audit.

@@ -11,6 +11,18 @@ trait FlatMapSyntax extends FlatMap.ToFlatMapOps {

implicit final def catsSyntaxFlatMapIdOps[A](a: A): FlatMapIdOps[A] =
new FlatMapIdOps[A](a)

implicit final def catsSyntaxFlatMapOps[F[_]: FlatMap, A](fa: F[A]): FlatMapOps[F, A] =
new FlatMapOps[F, A](fa)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are untested, because of deprecation


/** Alias for [[forEffect]]. */
@inline final def <*[A, B](fa: F[A])(fb: F[B]): F[A] =
forEffect(fa)(fb)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is untested because <* and << were before this PR.

Copy link
Contributor

@edmundnoble edmundnoble left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<3 <3 <3

@johnynek
Copy link
Contributor

👍

@LukaJCB LukaJCB dismissed johnynek’s stale review October 10, 2017 08:17

All changes addressed

@LukaJCB LukaJCB merged commit b7f15a1 into typelevel:master Oct 10, 2017
@stew stew removed the in progress label Oct 10, 2017
@LukaJCB LukaJCB deleted the remove-redundant-flatmap-operators branch October 10, 2017 08:18
@kailuowang kailuowang added this to the 1.0.0-RC1 milestone Oct 13, 2017
@mpilquist mpilquist mentioned this pull request Oct 27, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Deprecate >> and << in favor of *> and <*
6 participants