Skip to content

Commit

Permalink
Merge pull request #3405 from armanbilge/topic/revert-3214
Browse files Browse the repository at this point in the history
Remove `IOLocal#scope`, revert #3214
  • Loading branch information
djspiewak authored Feb 6, 2023
2 parents 294f33c + a1be0fe commit 5f7b243
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 40 deletions.
3 changes: 1 addition & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -906,8 +906,7 @@ lazy val std = crossProject(JSPlatform, JVMPlatform, NativePlatform)
"cats.effect.std.Queue#DroppingQueue.onOfferNoCapacity"),
// introduced by #3347
// private stuff
ProblemFilters.exclude[MissingClassProblem](
"cats.effect.std.AtomicCell$Impl")
ProblemFilters.exclude[MissingClassProblem]("cats.effect.std.AtomicCell$Impl")
)
)
.jsSettings(
Expand Down
23 changes: 0 additions & 23 deletions core/shared/src/main/scala/cats/effect/IOLocal.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package cats.effect

import cats.data.AndThen
import cats.syntax.functor._

/**
* [[IOLocal]] provides a handy way of manipulating a context on different scopes.
Expand Down Expand Up @@ -191,28 +190,6 @@ sealed trait IOLocal[A] { self =>
*/
def getAndReset: IO[A]

/**
* Creates a scope with the given value. The original value is restored upon the finalization
* of a resource. It means all changes made inside of the resource will not be propagated to
* the outside.
*
* @example
*
* {{{
* for {
* local <- IOLocal(42)
* _ <- local.get // returns 42
* _ <- local.scope(current => current + 1).surround(local.getAndSet(1)) // returns 43
* _ <- local.get // returns 42, even though 1 was set inside of the resource
* } yield ()
* }}}
*
* @param f
* the function to make a new scope
*/
final def scope(value: A): Resource[IO, Unit] =
Resource.make(getAndSet(value))(p => set(p)).void

/**
* Creates a lens to a value of some type `B` from current value and two functions: getter and
* setter.
Expand Down
16 changes: 1 addition & 15 deletions tests/shared/src/test/scala/cats/effect/IOLocalSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
package cats
package effect

import cats.syntax.semigroup._

import scala.annotation.tailrec

class IOLocalSpec extends BaseSpec {
Expand Down Expand Up @@ -79,7 +77,7 @@ class IOLocalSpec extends BaseSpec {
}
}

private def ioLocalTests[A, B: Semigroup, C: Eq: Show](
private def ioLocalTests[A, B, C: Eq: Show](
name: String,
localF: A => IO[(IOLocal[B], IOLocal[C])]
)(
Expand Down Expand Up @@ -160,18 +158,6 @@ class IOLocalSpec extends BaseSpec {
io must completeAs(checkA(initial))
}

"do not leak internal updates outside of a scope" in ticked { implicit ticker =>
val io = localF(initial).flatMap {
case (writer, reader) =>
for {
inside <- writer.scope(update).surround(reader.get <* writer.set(update |+| update))
outside <- reader.get
} yield (inside, outside)
}

io must completeAs((checkB(update), checkA(initial)))
}

}

}

0 comments on commit 5f7b243

Please sign in to comment.