Skip to content

Foldable instance for List breaks substitution #1716

Closed
@noelwelsh

Description

@noelwelsh

The Foldable instance for List breaks substitution, as the following program demonstrates. The value of result.value differs between the first and subsequent calls.

import cats.instances.list._
import cats.Eval
import cats.syntax.foldable._

val result  = List.range(0,10).foldM(List.empty[Int])((accum, elt) => Eval.always(elt :: accum))

result.value
// res: List[Int] = List(9, 8, 7, 6, 5, 4, 3, 2, 1, 0)

result.value
// res: List[Int] = List(0)

I haven't had time to debug but I suspect it relates to the use of a mutable ListBuffer in the implementation of tailRecM.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions