-
Notifications
You must be signed in to change notification settings - Fork 17
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 Enumerator.ensureEval #106
Conversation
If this looks basically sane, I'll add a test of say a |
looks like a linter error. I'll fix if you think this approach looks okay. |
Thanks, @johnynek! |
Will merge when green (it does look like it's just a line-length issue, although I'm not sure why 2.11 is showing up as passing…). |
Actually, as you can see here, laziness in captureEffect is not enough. We also assume that recursive flatMap is safe. I think we should put this on pause, but I am leaving it here. To really make this work, I think we need cats 0.7.0 and replace the flatMap with tailRecM, and then we expect a |
@johnynek I've been thinking some more about this in the context of the related Cats issue, and I'm wondering how necessary you think it is to support stack safety with It's just so much simpler to say that |
I don't think we should trampoline, but I think we should use tailRecM As I'm sure you know, iteratee is the motivating example for me wanting to I mean, if tailRecM is not suitable for Iteratee, who exactly is it useful
|
@johnynek If Cats goes the I still don't really like it, though. To take an analogy—at some point someone opened an issue against circe where they were passing But I'm realizing that's not a popular position, and I'm happy to go along with what everyone else wants if necessary. :) |
In light of the solution being proposed (all |
okay, I'll update this with your latest fixes, and see if we can have a design where |
@johnynek Great, thanks! I'm going to go ahead and publish a new milestone, and I'd like to try to get 0.6.0 out as early as possible this week, but there's not a huge rush from my perspective. |
well, from my perspective, as we are adopting more of these libraries at work, and across several differently sized repos, version churn is a significant cost. So, the fewer times we have to change code the better. So, |
Current coverage is 0.00% (diff: 0.00%)
|
import java.io.File | ||
|
||
class TryTests extends BaseSuite { | ||
val tryModule = FileModule[Try] |
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.
would be interesting to benchmark this. My guess is a strict monad (like Option, Either or Try) could be faster for single threaded applications.
@@ -18,37 +18,45 @@ import scala.collection.JavaConverters._ | |||
import scala.util.{ Left, Right } | |||
|
|||
trait FileModule[F[_]] { this: Module[F] { type M[f[_]] <: MonadError[f, Throwable] } => | |||
protected def captureEffect[A](a: => A): F[A] | |||
protected def captureEffect[A](a: => A): F[A] = F.catchNonFatal(a) |
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.
@johnynek What do you think about providing this operation via a new type class, so we could follow the pattern in iteratee-core, where all of the operations are available on a FileEnumerators
object, and FileModule
is just a syntactic convenience? The implementations would be more or less the same, and that approach would be likely to involve fewer API changes if Cats introduces a more general solution to the problem.
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.
So, as I have discussed on the thread here:
I don't see why F.catchNonFatal(a)
possibly coupled with Eval.always
is not what we want in practice.
I feel like making a typeclass creates a veneer of rigor that is actually absent, and I'd frankly rather just stick to the mechanical style of Eval + MonadError, or Eval + Monad if it can't fail (but very few true effects can't fail).
If we have a typeclass here, we can certainly generate those from something in cats, but that feels more hypothetical to me.
Given that this only adds liftMEval
which I think is useful to have for laziness if nothing else, and it leaves the existing modules as is, it seems a conservative approach.
@travisbrown rather than rebase, can you just use github's squash-merge when you merge so I don't need to bother? That's easy, right? |
(the green button now gives you the option to squash). |
Thanks, @johnynek—merging this now, will follow up with a PR with some name changes (for |
sounds good. Thanks |
Addresses #105