Skip to content

Chain in Cats built for Scala 2.12 can keep a mutable collection #4162

@satorg

Description

@satorg

Example (see in Scastie):

import cats.data.Chain

// Should contain lease 2 elements initially to enforce Chain.Wrap
val buff = scala.collection.mutable.ListBuffer(1, 2) 
val chain = Chain.fromSeq(buff)

// Add more elements to the source buff
buff += 3
buff += 4

println(chain)
// Chain(1, 2, 3, 4)

This is because Chain.fromSeq takes a default Seq (defined in Predef) which in Scala 2.12 is just scala.collection.Seq which in turn can be both ..mutable.Seq and ..immutable.Seq.

This snippet does not compile in Scala 2.13 and above.

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