Why scalaz |+| operator only doesn't work with Maps which value are Seq?

651 views Asked by At

I have two maps as follows.

import scalaz._, Scalaz._

val map1: Map[String, Seq[String]] = Some value
val map2: Map[String, Seq[String]] = Somve Value

This compiles fine and everything works as expected.

// Compiles
map1.mapValues{_.toList} |+| map2.mapValues{_.toList}

But this one doesn't compile (cannot resolve symbol |+|), I'm wondering why?

// Doesn't compile
map1 |+| map2

Update: I found this great article that answers why the compile error happens and that's basically, as people mentioned in comment section, Seq is not a monoid: Why is List a Semigroup but Seq is not?

Now my question is: Does that mean I have to convert my Seq (IndexedSeq have the same problem) to List and back to Seq again (the Seqs are actually IndexedSeq and I should keep them as IndexedSeq for performance reasons). Is there any work around this other than writing my own map merger code?

0

There are 0 answers