-
Notifications
You must be signed in to change notification settings - Fork 508
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
Add IO#to conversion method #50
Changes from 1 commit
be41c03
ef3a870
af72b60
f7e1d41
3660c5e
8dc3cc8
1822867
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -352,10 +352,27 @@ class IOTests extends BaseTestsSuite { | |
f.value shouldEqual Some(Success(100)) | ||
} | ||
|
||
testAsync("io.to[IO] works") { implicit ec => | ||
def repeatedTransformLoop[A](n: Int, io: IO[A]): IO[A] = | ||
io.to[IO].flatMap { x => | ||
if (n <= 0) IO.pure(x).to[IO] | ||
else repeatedTransformLoop(n - 1, io) | ||
} | ||
|
||
testAsync("io.to[IO] <-> io") { implicit ec => | ||
check { (io: IO[Int]) => io.to[IO] <-> io } | ||
} | ||
|
||
testAsync("sync.to[IO] is stack-safe") { implicit ec => | ||
// Override default generator to only generate | ||
// synchronous instances that are stack-safe | ||
implicit val arbIO: Arbitrary[IO[Int]] = | ||
Arbitrary(Gen.delay(genSyncIO[Int])) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Out of curiosity, with the new implementation, does this work even with the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, it's the same thing. Depending on There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cool, thanks. |
||
|
||
check { (io: IO[Int]) => | ||
repeatedTransformLoop(10000, io) <-> io | ||
} | ||
} | ||
|
||
testAsync("async.to[IO] is stack-safe if the source is") { implicit ec => | ||
// Stack-safe async IO required | ||
def async(a: Int) = IO.async[Int] { cb => | ||
|
@@ -365,15 +382,8 @@ class IOTests extends BaseTestsSuite { | |
}) | ||
} | ||
|
||
def loop(n: Int, io: IO[Int]): IO[Int] = | ||
io.to[IO].flatMap { x => | ||
if (n <= 0) IO.pure(x).to[IO] | ||
else loop(n - 1, io) | ||
} | ||
|
||
val f = loop(10000, async(99)).unsafeToFuture() | ||
val f = repeatedTransformLoop(10000, async(99)).unsafeToFuture() | ||
ec.tick() | ||
|
||
f.value shouldEqual Some(Success(99)) | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 This is exactly what I had in mind.