typelevel / typelevel/cats

Typeclass instances for `ZipLazyList` and `ZipStream` seem to be unlawful

Open
#4,830 12 comments 0 reactions 1 assignee View on GitHub

@satorg is already working on this.

Since Mar 3, 2026.

Dominant language
Scala
Stars
5.5k
Forks
1.2k
Avg merge
2d 10h
Merged PRs (30d)
5

Description

There are Alternative and CommutativeApplicative instances for both ZipLazyList and ZipStream:

https://github.com/typelevel/cats/blob/a69b592b0dbedb0c42cd5bb47bad77a2a0d9b772/core/src/main/scala-2.13%2B/cats/data/ZipLazyList.scala#L31

https://github.com/typelevel/cats/blob/a69b592b0dbedb0c42cd5bb47bad77a2a0d9b772/core/src/main/scala-2.12/cats/data/ZipStream.scala#L31

https://github.com/typelevel/cats/blob/a69b592b0dbedb0c42cd5bb47bad77a2a0d9b772/core/src/main/scala-2.13%2B/cats/data/ZipStream.scala#L33

However, the corresponding laws have never been verified. The existing tests for both ZipLazyList and ZipStream check laws only up to CommutativeApply, with the following comment:

Can't test applicative laws as they don't terminate

https://github.com/typelevel/cats/blob/a69b592b0dbedb0c42cd5bb47bad77a2a0d9b772/tests/shared/src/test/scala-2.13%2B/cats/tests/LazyListSuite.scala#L71-L72

https://github.com/typelevel/cats/blob/a69b592b0dbedb0c42cd5bb47bad77a2a0d9b772/tests/shared/src/test/scala/cats/tests/StreamSuite.scala#L57-L58

Moreover, ZipList, ZipVector, ZipSeq, as well as their *NonEmpty* counterparts, define instances only up to CommutativeApply.

Taken together, this strongly suggests that ZipLazyList and ZipStream cannot lawfully provide anything stronger than CommutativeApply.

Perhaps the Alternative and CommutativeApplicative instances for ZipLazyList and ZipStream should be moved to alleycats-core, while cats-core should retain only CommutativeApply.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.