-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Unexpected behavior of NonEmptyMap #3117
Comments
should not foldable of NonEmptyMap fold over tuple Yep,
btw. standard scala map does it correctly |
This seems like a good argument against this newtype encoding (which to be honest I've always hated, so this feels kind of vindicating). I think the issue is scala> import cats.data.NonEmptyMap
import cats.data.NonEmptyMap
scala> import cats.instances.int._
import cats.instances.int._
scala> val nem: NonEmptyMap[Int, String] = NonEmptyMap.of(1 -> "one", 2 -> "two")
nem: cats.data.NonEmptyMap[Int,String] = Map(1 -> one, 2 -> two)
scala> nem.find(_ == "one")
res0: Option[(Int, String)] = Some((1,one))
scala> import cats.syntax.foldable._
import cats.syntax.foldable._
scala> nem.find(_ == "one")
res1: Option[String] = Some(one)
scala> import NonEmptyMap._
import NonEmptyMap._
scala> nem.find(_ == "one")
res2: Option[(Int, String)] = Some((1,one)) I think we're stuck with this (at least until Cats 3), since the imported |
I noticed that NEM seems to prefer
.find
on Foldable rather on the concrete type whencats.implicits._
or more concretelyimport cats.instances.int._
is in scope. This confused me since I had everything working, I pulled in cats.implicits._ for some other reason and this broke the compile. What is the expected order of preference here?scala version 2.13
cats version 2.0.0
The text was updated successfully, but these errors were encountered: