-
Notifications
You must be signed in to change notification settings - Fork 532
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 a map
method directly onto Resource
#437
Merged
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
619087d
Add a `map` method directly onto `Resource`
andimiller cb35949
Implement Resource.map using pure rather than makeCase
andimiller 2831aa8
Weaken F on Resource.map to Applicative, since pure only needs Applic…
andimiller 6cbfc56
whitespace
andimiller bff26b1
Use Resource.map within Resource Monad
andimiller d0877cd
Give Resource.map more useful scaladoc
andimiller File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -87,6 +87,13 @@ class ResourceTests extends BaseTestsSuite { | |
Resource.liftF(fa).use(IO.pure) <-> fa | ||
} | ||
} | ||
testAsync("map should be the same as going via Monad") { implicit ec => | ||
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. Instead of adding this test, a better idea would be to override |
||
val monad = implicitly[Monad[Resource[IO, ?]]] | ||
check { fa: IO[String] => | ||
Resource.liftF(fa).map(_.toLowerCase).use(IO.pure) <-> | ||
monad.map(Resource.liftF(fa))(_.toLowerCase).use(IO.pure) | ||
} | ||
} | ||
|
||
testAsync("allocated produces the same value as the resource") { implicit ec => | ||
check { resource: Resource[IO, Int] => | ||
|
@@ -117,4 +124,5 @@ class ResourceTests extends BaseTestsSuite { | |
val suspend = Resource.suspend[IO, Int](IO.raiseError(exception)) | ||
suspend.attempt.use(IO.pure).unsafeRunSync() shouldBe Left(exception) | ||
} | ||
|
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The reason for why this
map
is provided shouldn't be exposed in ScalaDoc, especially since now this implementation becomes the "source of truth" forResource
.Just do something generic like ...
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.
But I think we need another ScalaDoc comment, on
Resource
class, mentioning:-Ypartial-unification
import cats.implicits._
... to unlock all available operations.