Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove IOLocal#scope, revert #3214 #3405

Merged
merged 1 commit into from
Feb 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)))
}

}

}