How to import TripleEquals (===) only?

44 views
Skip to first unread message

Andreas Joseph Krogh

unread,
Mar 15, 2016, 5:40:33 PM3/15/16
to scalaz
Hi.

I'd like to import as specific as possible the === operator, how do I do that?

Thanks.

--
Andreas

Brian McKenna

unread,
Mar 15, 2016, 5:50:23 PM3/15/16
to sca...@googlegroups.com

import scalaz.syntax.equal._

--
You received this message because you are subscribed to the Google Groups "scalaz" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scalaz+un...@googlegroups.com.
To post to this group, send email to sca...@googlegroups.com.
Visit this group at https://groups.google.com/group/scalaz.
For more options, visit https://groups.google.com/d/optout.

Parakhonskiy Gleb

unread,
Mar 16, 2016, 4:16:47 AM3/16/16
to scalaz
Hi, Brian's answer will surely do the thing
For the sake of completeness, threre's another way: 
import scalaz.Scalaz.ToEqualOps

Andreas Joseph Krogh

unread,
Mar 16, 2016, 6:07:53 PM3/16/16
to scalaz
Hm, sorry but none of these worked.

import scalaz.Scalaz.ToEqualOps
val f = "nissefisk"
val i = 123
val t = f === i

Error:(29, 13) value === is not a member of String
        val t = f === i
                  ^

If I replace with:
import scalaz.Scalaz._

I get correct error:
Error:(29, 17) type mismatch;
found : Int
required: String
val t = f === i
^

What am I missing?

Thanks.

Robert Norris

unread,
Mar 16, 2016, 6:18:08 PM3/16/16
to sca...@googlegroups.com

You need the syntax for the typeclass as well as the instances for types you'd like to compare.

scala> import scalaz.syntax.equal._ // syntax for the typeclass
import scalaz.syntax.equal._

scala> import scalaz.std.string._ // instances for String
import scalaz.std.string._

scala> "abc" === "abc"
res0: Boolean = true

scala> "abc" =/= "def"
res1: Boolean = true

scala> "abc" === 1
<console>:14: error: type mismatch;
 found   : Int(1)
 required: String
              "abc" === 1
                        ^






Andreas Joseph Krogh

unread,
Mar 16, 2016, 6:36:33 PM3/16/16
to scalaz
Thanks!
Reply all
Reply to author
Forward
0 new messages