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

Add Resource.evalTap #490

Merged
merged 1 commit into from
May 1, 2019
Merged

Conversation

nigredo-tori
Copy link

A cross between flatTap and evalMap. Use case - an action returning a temporary resource with custom setup. For me this pattern pops up all the time when writing logic that uses temporary files (create a temporary file, write some data to it, yield the file).

@codecov-io
Copy link

Codecov Report

Merging #490 into master will decrease coverage by 0.28%.
The diff coverage is 100%.

@@            Coverage Diff             @@
##           master     #490      +/-   ##
==========================================
- Coverage   89.81%   89.53%   -0.29%     
==========================================
  Files          70       70              
  Lines        2043     2044       +1     
  Branches      213      198      -15     
==========================================
- Hits         1835     1830       -5     
- Misses        208      214       +6

@kubukoz
Copy link
Member

kubukoz commented Mar 7, 2019

Not sure if it's worth the effort - consecutive evalTap invocations like evalMap(f).evalMap(g).use(h) are pretty much like use(a => f(a) *> g(a) *> h(a)). But if others feel like this is useful enough to be a new method, then I'm good :)

@nigredo-tori
Copy link
Author

consecutive evalTap invocations like evalMap(f).evalMap(g).use(h) are pretty much like use(a => f(a) *> g(a) *> h(a))

This works when you immediately do .use, but .evalTap is useful for more complex cases (like traversing a collection in Resource, or returning a prepared Resource from a function).

@mpilquist
Copy link
Member

👍 from me -- fs2 has evalTap as well:

// On Stream[F, O]
def evalTap[F2[x] >: F[x]: Functor](f: O => F2[Unit]): Stream[F2, O] =

@djspiewak
Copy link
Member

This is merged into series/1.x, but due to a snafu on my end, we didn't update the base before the merge. So this will eventually land in master, but only after the 1.3 release (soon™).

@djspiewak djspiewak merged commit 052ea86 into typelevel:master May 1, 2019
@nigredo-tori nigredo-tori deleted the resource-evaltap branch May 2, 2019 01:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants