Skip to content
Permalink
Browse files

Better import for other concurrent data types

  • Loading branch information...
amarrella committed Jan 23, 2019
1 parent 00b4e2b commit 52a310c9fe66700502f513ed7dfe771ecf0f2f8b
@@ -9,13 +9,14 @@ import fs2._
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.duration._
import cats.effect.concurrent
import cats.effect.concurrent.Semaphore
import cats.effect.concurrent.{ Deferred, Ref, Semaphore }
import fs2.concurrent.{ Signal, SignallingRef }

abstract class ConcurrentDataTypes[F[_]: Effect] {
// Ref
val ref: F[cats.effect.concurrent.Ref[F, Int]] = cats.effect.concurrent.Ref.of(1)
cats.effect.concurrent.Ref.of[F, Int](1)
cats.effect.concurrent.Ref.of(1)
val ref: F[Ref[F, Int]] = Ref.of(1)
Ref.of[F, Int](1)
Ref.of(1)
ref.map(_.set(1))
ref.map(_.setAsync(1))
val a = ref.flatMap(_.update(_ + 1))
@@ -24,10 +25,10 @@ abstract class ConcurrentDataTypes[F[_]: Effect] {
val d = ref.flatMap(_.tryModify(i => (i, "a")))

// Deferred
val e: F[cats.effect.concurrent.Deferred[F, Int]] = cats.effect.concurrent.Deferred[F, Int]
val e2: F[cats.effect.concurrent.Deferred[F, Int]] = cats.effect.concurrent.Deferred
val f: F[cats.effect.concurrent.Deferred[F, Int]] = promise[F, Int]
val f2: F[cats.effect.concurrent.Deferred[F, Int]] = promise
val e: F[Deferred[F, Int]] = Deferred[F, Int]
val e2: F[Deferred[F, Int]] = Deferred
val f: F[Deferred[F, Int]] = promise[F, Int]
val f2: F[Deferred[F, Int]] = promise
e.map(_.get)
def scheduler: Timer[F]
e.map(_.timeout(1.second))
@@ -37,8 +38,8 @@ abstract class ConcurrentDataTypes[F[_]: Effect] {
Semaphore(2)

// Signal
val sig: fs2.concurrent.Signal[F, Int] = Signal.constant[F, Int](1)
val sigRef: F[fs2.concurrent.SignallingRef[F, Int]] = fs2.concurrent.SignallingRef(1)
val sig: Signal[F, Int] = Signal.constant[F, Int](1)
val sigRef: F[SignallingRef[F, Int]] = SignallingRef(1)

// Queue
val q: F[fs2.concurrent.Queue[F, Int]] = fs2.concurrent.Queue.unbounded
@@ -132,15 +132,15 @@ object ConcurrentDataTypesRules {
replaceSemaphore :: renameQueue :: renameTopic :: t.collect {
// fs2 Ref -> cats effect Ref
case Term.Apply(refMatcher(n: Term.Name), _) =>
Patch.replaceTree(n, "cats.effect.concurrent.Ref.of")
Patch.replaceTree(n, "Ref.of") + Patch.addGlobalImport(Symbol("cats/effect/concurrent/Ref."))
case Type.Apply(t @ Type.Name("Ref"), _) =>
Patch.replaceTree(t, "cats.effect.concurrent.Ref")
Patch.replaceTree(t, "Ref") + Patch.addGlobalImport(Symbol("cats/effect/concurrent/Ref."))
case Term.Apply(Term.ApplyType(r @ refMatcher(_), _), _) =>
Patch.replaceTree(r, "cats.effect.concurrent.Ref")
Patch.replaceTree(r, "Ref") + Patch.addGlobalImport(Symbol("cats/effect/concurrent/Ref."))
case Term.Apply(r @ Term.Name("refOf"), _) =>
Patch.replaceTree(r, "cats.effect.concurrent.Ref.of")
Patch.replaceTree(r, "Ref.of") + Patch.addGlobalImport(Symbol("cats/effect/concurrent/Ref."))
case Term.Apply(Term.ApplyType(r @ Term.Name("refOf"), _), _) =>
Patch.replaceTree(r, "cats.effect.concurrent.Ref.of")
Patch.replaceTree(r, "Ref.of") + Patch.addGlobalImport(Symbol("cats/effect/concurrent/Ref."))
case setSyncMatcher(Term.Apply(t @ Term.Select(_, s), _)) =>
Patch.replaceTree(s, "set")
case setAsyncMatcher(Term.Apply(t @ Term.Select(_, s), _)) =>
@@ -160,25 +160,25 @@ object ConcurrentDataTypesRules {

// Promise -> Deferred
case t @ Term.Select(promiseMatcher(_), Term.Name("empty")) =>
Patch.replaceTree(t, "cats.effect.concurrent.Deferred")
Patch.replaceTree(t, "Deferred") + Patch.addGlobalImport(Symbol("cats/effect/concurrent/Deferred."))
case promiseMatcher(t @ Type.Name("Promise")) =>
Patch.replaceTree(t, s"cats.effect.concurrent.Deferred")
Patch.replaceTree(t, s"Deferred") + Patch.addGlobalImport(Symbol("cats/effect/concurrent/Deferred."))
case t @ promiseLowercaseMatcher(_) =>
Patch.replaceTree(t, "cats.effect.concurrent.Deferred")
Patch.replaceTree(t, "Deferred") + Patch.addGlobalImport(Symbol("cats/effect/concurrent/Deferred."))
case cancellableGetMatcher(Term.Select(_, s)) =>
Patch.replaceTree(s, "get")
case timedGetMatcher(s @ Term.Apply(Term.Select(pre, Term.Name("timedGet")), List(d, _))) =>
Patch.replaceTree(s, s"${pre}.timeout($d)")

// Signal
case t @ immutableSignalMatcher(_: Term.Name) =>
Patch.replaceTree(t, "fs2.concurrent.Signal")
Patch.replaceTree(t, "Signal") + Patch.addGlobalImport(Symbol("fs2/concurrent/Signal."))
case immutableSignalMatcher(Type.Apply(s, _)) =>
Patch.replaceTree(s, "fs2.concurrent.Signal")
Patch.replaceTree(s, "Signal") + Patch.addGlobalImport(Symbol("fs2/concurrent/Signal."))
case mutableSignalMatcher(Term.Apply(s, _)) =>
Patch.replaceTree(s, "fs2.concurrent.SignallingRef")
Patch.replaceTree(s, "SignallingRef") + Patch.addGlobalImport(Symbol("fs2/concurrent/SignallingRef."))
case mutableSignalMatcher(Type.Apply(s, _)) =>
Patch.replaceTree(s, "fs2.concurrent.SignallingRef")
Patch.replaceTree(s, "SignallingRef") + Patch.addGlobalImport(Symbol("fs2/concurrent/SignallingRef."))

// Imports
case i: Import =>

0 comments on commit 52a310c

Please sign in to comment.
You can’t perform that action at this time.