Skip to content

Commit

Permalink
Add test to show mutability breaks traverse
Browse files Browse the repository at this point in the history
  • Loading branch information
armanbilge committed Nov 10, 2023
1 parent a1c9ff5 commit 2210d82
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions tests/shared/src/test/scala/cats/tests/ListSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,16 @@ class ListSuite extends CatsSuite {

assert(sumAll == lst.sum)
}

test("list traverse list".only) {
// cheating!!!
implicit val listMonad: Monad[List] = new cats.StackSafeMonad[List] {
def pure[A](a: A) = List(a)
def flatMap[A, B](la: List[A])(f: A => List[B]) = la.flatMap(f)
}
val traversed = Traverse[List].traverse(List(()))(_ => List((), ()))
assertEquals(traversed, List(List(()), List(())))
}
}

final class ListInstancesSuite extends munit.FunSuite {
Expand Down

0 comments on commit 2210d82

Please sign in to comment.