Skip to content

Commit

Permalink
Add todo for resource factory method
Browse files Browse the repository at this point in the history
  • Loading branch information
mbore committed Oct 12, 2021
1 parent 0d2d0d0 commit 42b5eea
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import com.softwaremill.macwire.catseffectsupport._

#include commonSimpleClasses
import cats.effect._

val factoryParams = scala.collection.mutable.ListBuffer[B]()

object Test {
def theA(b: B): A = { factoryParams.append(b); A() }
val theB: Resource[IO, B] = Resource.pure(B())
val theC: Resource[IO, C] = wireApp[C](theA _, theB)
}

val theC: C = {
import cats.effect.unsafe.implicits.global
Test.theC.allocated.unsafeRunSync()._1
}

require(theC.a != null)
require(theC.b != null)

require(factoryParams.length == 1)
require(factoryParams.head eq theC.b)
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import cats.effect._
val allocated = scala.collection.mutable.ListBuffer[String]()

object Test {
val theA: Resource[IO, A] = Resource.make(IO { allocated.addOne("A"); A() })(_ => IO.unit)
val theA: Resource[IO, A] = Resource.make(IO { allocated.append("A"); A() })(_ => IO.unit)
val theE: Resource[IO, E] = wireApp[E](theA)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import cats.effect._
val factoryParams = scala.collection.mutable.ListBuffer[B]()

object Test {
def theA(b: B): A = { factoryParams.addOne(b); A() }
def theA(b: B): Resource[IO, A] = { factoryParams.append(b); Resource.pure(A()) }
val theB: Resource[IO, B] = Resource.pure(B())
val theC: Resource[IO, C] = wireApp[C](theA _, theB)
}
Expand Down

0 comments on commit 42b5eea

Please sign in to comment.