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

Add Align typeclass #3076

Open
wants to merge 10 commits into
base: master
from

Conversation

@LukaJCB
Copy link
Member

commented Sep 20, 2019

Should fix #1263 while replacing #1755 by @julianmichael who did most of the work.

LukaJCB added 2 commits Sep 20, 2019
@LukaJCB LukaJCB force-pushed the align branch from a1ca7fa to 909a33a Sep 20, 2019
@codecov-io

This comment has been minimized.

Copy link

commented Sep 20, 2019

Codecov Report

Merging #3076 into master will increase coverage by 0.05%.
The diff coverage is 97.29%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3076      +/-   ##
==========================================
+ Coverage   93.17%   93.22%   +0.05%     
==========================================
  Files         372      375       +3     
  Lines        7179     7282     +103     
  Branches      207      195      -12     
==========================================
+ Hits         6689     6789     +100     
- Misses        490      493       +3
Flag Coverage Δ
#scala_version_212 93.56% <97%> (+0.04%) ⬆️
#scala_version_213 90.92% <95.49%> (+0.06%) ⬆️
Impacted Files Coverage Δ
core/src/main/scala/cats/data/NonEmptyChain.scala 85.39% <ø> (ø) ⬆️
.../main/scala-2.13+/cats/data/NonEmptyLazyList.scala 60.86% <ø> (ø) ⬆️
core/src/main/scala/cats/data/Validated.scala 100% <100%> (ø) ⬆️
core/src/main/scala/cats/data/NonEmptyList.scala 99.35% <100%> (+0.02%) ⬆️
...src/main/scala-2.13+/cats/instances/lazyList.scala 100% <100%> (ø) ⬆️
core/src/main/scala/cats/instances/either.scala 100% <100%> (ø) ⬆️
core/src/main/scala/cats/Apply.scala 78.94% <100%> (+3.94%) ⬆️
core/src/main/scala/cats/Align.scala 100% <100%> (ø)
core/src/main/scala/cats/SemigroupK.scala 100% <100%> (ø) ⬆️
core/src/main/scala/cats/data/Const.scala 100% <100%> (ø) ⬆️
... and 14 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 eb52c0b...6e7d2b4. Read the comment docs.

@LukaJCB LukaJCB force-pushed the align branch from 8a94d12 to c5084bf Sep 25, 2019
@LukaJCB LukaJCB requested a review from kailuowang Sep 25, 2019
@@ -401,6 +401,9 @@ def mimaSettings(moduleName: String) =
exclude[MissingClassProblem](
"cats.kernel.compat.scalaVersionMoreSpecific$suppressUnusedImportWarningForScalaVersionMoreSpecific"
)
) ++ //abstract package private classes
Seq(
exclude[DirectMissingMethodProblem]("cats.data.AbstractNonEmptyInstances.this")

This comment has been minimized.

Copy link
@kailuowang

kailuowang Oct 8, 2019

Member

Are we sure this doesn't break BC? If we are sure maybe add a test in binCompatTest? If not can we just add a separate method to provide the instance for Align?

This comment has been minimized.

Copy link
@LukaJCB

LukaJCB Oct 10, 2019

Author Member

I added some tests there, I think that should suffice, WDYT?

This comment has been minimized.

Copy link
@kailuowang

kailuowang Oct 11, 2019

Member

I think that shall do. thanks!
On a slightly related note, since we have been updating the build, I am a bit nervous that if something breaks binCompatTest, we wouldn't know. I'll create an issue.

LukaJCB added 2 commits Oct 8, 2019
@LukaJCB LukaJCB requested a review from kailuowang Oct 10, 2019

var result: LazyList[C] = LazyList.empty

while (iterA.hasNext || iterB.hasNext) {

This comment has been minimized.

Copy link
@kailuowang

kailuowang Oct 11, 2019

Member

This will trigger evaluation of all items right? I imagine we should be able to write a lazy implementation right?

This comment has been minimized.

Copy link
@LukaJCB

LukaJCB Oct 11, 2019

Author Member

Oh does it? I haven't actually looked at how LazyList works at all. Help welcome :)

This comment has been minimized.

Copy link
@kailuowang

kailuowang Oct 11, 2019

Member

me neither. but I think you can create a new iterator something like

val alighIterator = new Iterator[C] {
    def hasNext: Boolean = iterA.hasNext || iterB.hasNext
    def next(): C   = 
            val ior =
               if (iterA.hasNext && iterB.hasNext) Ior.both(iterA.next(), iterB.next())
               else if (iterA.hasNext) Ior.left(iterA.next())
               else Ior.right(iterB.next())
           f(ior)
}

LazyList.from(alignIterator)

This comment has been minimized.

Copy link
@LukaJCB

LukaJCB Oct 15, 2019

Author Member

Thanks this seems to work just fine :)

LukaJCB added 2 commits Oct 15, 2019
@kailuowang

This comment has been minimized.

Copy link
Member

commented Oct 15, 2019

just added some more additional comments. Sorry I couldn't find the chunk of time to review it in one go.

Copy link
Member

left a comment

Thanks!

*/
@typeclass trait Align[F[_]] {

def functor: Functor[F]

This comment has been minimized.

Copy link
@djspiewak

djspiewak Oct 18, 2019

Member

Maybe this was already discussed, but is there a particular reason to make this compositional rather than inherited? Is it because Align is a leaf typeclass (a la Traverse)?

This comment has been minimized.

Copy link
@LukaJCB

LukaJCB Oct 18, 2019

Author Member

That's exactly the reason :)

This comment has been minimized.

Copy link
@djspiewak

djspiewak Oct 18, 2019

Member

Shouldn't we try to keep the encodings uniform though? After all, Traverse has this same problem, but it still uses subtyping.

This comment has been minimized.

Copy link
@LukaJCB

LukaJCB Oct 19, 2019

Author Member

I think we should move away from it. We're already doing this for FunctorFilter, TraverseFilter, Representable and probably others :)

This comment has been minimized.

Copy link
@LukaJCB
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.