Skip to content

GenCodec for Seq creates a Vector instead of List when reading #76

Closed
@ghik

Description

@ghik

Originally reported in #62

Technically, this is not a bug - GenCodec.read[Seq[A]] is free to choose whatever implementation of Seq it wants. However, this is non-intuitive because the standard Seq(...) factory creates a List by default.

It seems that the problem stems from an inconsistency in Scala collections library. GenCodec.seqCodec[Seq,A] is based on implicit instance of CanBuildFrom[Nothing,A,Seq[A]] which, for whatever reason, creates a Vector ¯\_(ツ)_/¯. This quirk can manifest in simpler examples, e.g.

scala> Seq(1,2,3)
res19: Seq[Int] = List(1, 2, 3)

scala> Seq(1,2,3).to[Seq]
res18: Seq[Int] = Vector(1, 2, 3)

So I'm not sure what to do about it yet, because it's not clear to me what would be the "correct" behaviour here. If we patched GenCodec specifically for Seq then we'd have to look for all other possible similar inconsistencies in the collections library and patch them accordingly...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions