- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
[scala-language] Seq[Set].flatten => error: could not find implicit value for parameter asTraversable ?
Fri, 2011-01-28, 16:49
Hello,
I just found that I'm not able to do a flatten on a Seq of Set, and that
seems really strange as I'm able to flatten a Seq of Iterables.
Is it related to http://lampsvn.epfl.ch/trac/scala/ticket/3813 ?
If not, could someone explain me what is the reason for that ?
8<---------- REPL session ----------------
Welcome to Scala version 2.8.1.final (Java HotSpot(TM) Server VM, Java
1.6.0_23).
Type in expressions to have them evaluated.
Type :help for more information.
scala> Seq( Set("a"), Set(), Set("b", "a") ).flatten
:6: error: could not find implicit value for parameter
asTraversable: (scala.collection.immutable.Set[_ <: java.lang.String])
=> Traversable[B]
Seq( Set("a"), Set(), Set("b", "a") ).flatten
^
scala> Seq( Seq("a"), Seq(), Seq("b", "a") ).flatten
res1: Seq[java.lang.String] = List(a, b, a)
scala> Set( Seq("a"), Seq(), Seq("b", "a") ).flatten
res2: scala.collection.immutable.Set[java.lang.String] = Set(a, b)
scala> Seq( Seq("a"), Seq(), Seq("b", "a") ).flatMap( _.toSeq )
res3: Seq[java.lang.String] = List(a, b, a)
Seq( Iterable("a"), Iterable("a", "b") ).flatten
res4: Seq[java.lang.String] = List(a, a, b)
Seq( Set("a"):Iterable[String], Set():Iterable[String], Set("b",
"a"):Iterable[String] ).flatten
res5: Seq[String] = List(a, b, a)
8<---------- /REPL session ----------------
Thanks,
Fri, 2011-01-28, 17:17
#2
Re: [scala-language] Re: Seq[Set].flatten => error: could not fi
On 28/01/2011 16:55, Derek Williams wrote:
> I believe this is due to Set being invariant (or whatever it is called,
> I'm bad with jargon). This works:
>
> Seq( Set("a"), Set.empty[String], Set("b", "a") ).flatten
Ah, quite intersting. Thanks !
Fri, 2011-01-28, 18:27
#3
Re: [scala-language] Re: Seq[Set].flatten => error: could not fi
Oh, that's wise. It is invariant now.
2011/1/28 Derek Williams <derek@nebvin.ca>
--
Thanks,
-Vlad
2011/1/28 Derek Williams <derek@nebvin.ca>
I believe this is due to Set being invariant (or whatever it is called, I'm bad with jargon). This works:
Seq( Set("a"), Set.empty[String], Set("b", "a") ).flatten
--
Thanks,
-Vlad
Seq( Set("a"), Set.empty[String], Set("b", "a") ).flatten