fs2 icon indicating copy to clipboard operation
fs2 copied to clipboard

Inserting a map stops propagation of IOLocal

Open SystemFw opened this issue 2 years ago • 1 comments

Originally reported by @kamilkloch , I've done some minimisation. Reproduced in fs2 3.4.0, it seemed to work correctly on 3.0.2 (which I happened to have at hand). @Jasper-M points to https://github.com/typelevel/fs2/pull/2572 as the probable change.

def no =
    IOLocal(false).flatMap { local =>
      Stream
        .eval(local.set(true))
        .evalMap(_ => local.get)
        .map(x => x)
        .compile
        .toVector
    }
     .unsafeRunSync() // Vector(false)
     

  def yes =
    IOLocal(false).flatMap { local =>
      Stream
        .eval(local.set(true))
        .evalMap(_ => local.get)
        .compile
        .toVector
    }
     .unsafeRunSync() // Vector(true)

  def yes2 =
    IOLocal(false).flatMap { local =>
      Stream
        .eval(local.set(true) >> local.get)
        .compile
        .toVector
    }
     .unsafeRunSync() // Vector(true)

  def yes3 =
    IOLocal(false).flatMap { local =>
      (Stream.exec(local.set(true)) ++ Stream.eval(local.get))
        .compile
        .toVector
    }
     .unsafeRunSync() // Vector(true)

  def no2 =
    IOLocal(false).flatMap { local =>
      (Stream.exec(local.set(true)) ++ Stream.eval(local.get))
        .map(x => x)
        .compile
        .toVector
    }
     .unsafeRunSync() // Vector(false)

SystemFw avatar Jan 09 '23 13:01 SystemFw

Linking to:

  • https://github.com/typelevel/fs2/issues/2842

armanbilge avatar Jan 09 '23 14:01 armanbilge