exercises-cats icon indicating copy to clipboard operation
exercises-cats copied to clipboard

Foldable[T].traverse_ exercises accepts wrong answer as correct

Open Fabs opened this issue 6 years ago • 1 comments

On the exercise of Foldable traverse, it accepts a wrong answer as proper:

import cats.implicits._

def parseInt(s: String): Option[Int] =
  Either.catchOnly[NumberFormatException](s.toInt).toOption

Foldable[List].traverse_(List("1", "2", "3"))(parseInt) should be(Some(42))

Since traverse_ returns G[Unit], correct answer should be Some(()). But it is accepting Some of anything. Maybe it is even a bug on scalatest since on a workspace:

Foldable[List].traverse_(List("1", "2"))(parseInt) == Some(())
Foldable[List].traverse_(List("1", "2"))(parseInt) == Some(42)

Outputs:

true
false

image

Fabs avatar Nov 12 '17 12:11 Fabs

This also applies to the last Traversable exercise:

image

FRosner avatar Dec 19 '17 15:12 FRosner