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

Welcome, Alleycats #1984

Merged
merged 2 commits into from
Oct 26, 2017
Merged

Conversation

kailuowang
Copy link
Contributor

This PR moves alleycats into cats. We had some back and forth on this issue, but more and more evidences show it's more beneficial to have it inside cats repo.
It still has its own root package as alleycats and is only available when user explicitly add it as a dependency. So that users shall be careful when using instances defined here.

In the process, I removed the dependencies from alleycats to algebra, since 1) this should be solely for outlaw TCs in cats and 2) algebra depends on cats.kernel.
I believe it is fine since kittens (which I co-maintain) is the only project that uses alleycats and it doesn't use the part in alleycats that has those dependencies.

The immediate incentive is for us to move traverse and foldable instances for map and set in here.

@kailuowang
Copy link
Contributor Author

not sure if anyone wants to review all the alleycats code. I think only the build.sbt needs some review.

@kailuowang kailuowang mentioned this pull request Oct 20, 2017
12 tasks
import org.typelevel.discipline.Laws


trait FlatMapRecTests[F[_]] extends Laws {
Copy link
Contributor

Choose a reason for hiding this comment

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

this looks duplicative.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe this is the only way to test the one specific rule out of the rule set, in this case tailRecMConsistentFlatMap


// based upon foldRight of List in Cats
override def foldRight[A, B](fa: Iterable[A], lb: Eval[B])(f: (A, Eval[B]) => Eval[B]): Eval[B] = {
def loop(as: Iterable[A]): Eval[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 think this can actually be faster and get code-reuse if we use Foldable.iterateRight: https://github.com/typelevel/cats/blob/master/core/src/main/scala/cats/Foldable.scala#L508

object IterableInstances {
@export(Orphan)
implicit val exportIterableFoldable: Foldable[Iterable] =
new Foldable[Iterable] {
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 actually know why this shouldn't be in cats-core. What is the problem exactly? Foldable is lawless to begin with.

Copy link
Member

Choose a reason for hiding this comment

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

AFAIK Iterable's only method is iterator which isn't exactly referentially transparent, no?

Copy link
Contributor

Choose a reason for hiding this comment

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

But that is the only method you need to implement Foldable. And I don’t see why creating a new Iterator is not referentially transparent. It certainly is for all instances of Iterable is the standard library AFAIK.

Copy link
Contributor Author

@kailuowang kailuowang Oct 26, 2017

Choose a reason for hiding this comment

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

I don't know if all Iterable are actually Foldable, what about Stream?

Copy link
Contributor

Choose a reason for hiding this comment

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

Doesn’t Stream have a Foldable instance in cats already? What prevents it from being Foldable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

you are right, Stream is Foldable. Yeah, I don't see why we couldn't move Foldable ofIterable into core.

trait FoldableSyntax {
implicit class ExtraFoldableOps[F[_]: Foldable, A](fa: F[A]) {
def foreach(f: A => Unit): Unit =
fa.foldLeft(()) { (unit, a) => f(a); unit }
Copy link
Contributor

Choose a reason for hiding this comment

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

why aren't we returning f(a) here? I don't understand? It is Unit right?

LukaJCB
LukaJCB previously approved these changes Oct 21, 2017
def foldLeft[A, B](fa: Set[A], b: B)(f: (B, A) => B): B =
fa.foldLeft(b)(f)
def foldRight[A, B](fa: Set[A], lb: Eval[B])(f: (A, Eval[B]) => Eval[B]): Eval[B] =
Foldable.iterateRight(fa.iterator, lb)(f)
Copy link
Member

Choose a reason for hiding this comment

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

This one needs to be

Foldable.iterateRight(fa, lb)(f)

@codecov-io
Copy link

Codecov Report

Merging #1984 into master will decrease coverage by 0.67%.
The diff coverage is 17.5%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1984      +/-   ##
==========================================
- Coverage   96.21%   95.54%   -0.68%     
==========================================
  Files         272      285      +13     
  Lines        4627     4667      +40     
  Branches      115      115              
==========================================
+ Hits         4452     4459       +7     
- Misses        175      208      +33
Impacted Files Coverage Δ
alleycats-core/src/main/scala/alleycats/One.scala 0% <0%> (ø)
...eycats-core/src/main/scala/alleycats/Extract.scala 0% <0%> (ø)
...lleycats-core/src/main/scala/alleycats/ConsK.scala 0% <0%> (ø)
...lleycats-core/src/main/scala/alleycats/Empty.scala 0% <0%> (ø)
...leycats-core/src/main/scala/alleycats/EmptyK.scala 0% <0%> (ø)
...s-core/src/main/scala/alleycats/syntax/empty.scala 0% <0%> (ø)
...ore/src/main/scala/alleycats/syntax/foldable.scala 0% <0%> (ø)
alleycats-core/src/main/scala/alleycats/Pure.scala 0% <0%> (ø)
alleycats-core/src/main/scala/alleycats/Zero.scala 0% <0%> (ø)
...eycats-core/src/main/scala/alleycats/std/try.scala 0% <0%> (ø)
... and 16 more

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 55b51bd...a6e85dd. Read the comment docs.

@ghost
Copy link

ghost commented Oct 26, 2017

👍 Better late than never 😛

@johnynek
Copy link
Contributor

👍

@kailuowang kailuowang merged commit ef76136 into typelevel:master Oct 26, 2017
@kailuowang kailuowang deleted the move-in-alleycats branch October 26, 2017 17:38
@kailuowang kailuowang added this to the 1.0.0-RC1 milestone Oct 31, 2017
@longcao longcao mentioned this pull request Mar 19, 2018
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.

4 participants