-
Notifications
You must be signed in to change notification settings - Fork 523
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
IO.map should never be strictly evaluated #92
Comments
Nice catch, I definitely agree this should be fixed. I don't have a strong opinion on whether this should be in |
mpilquist
added a commit
that referenced
this issue
Dec 14, 2017
Fix #92: Sync.map should suspend evaluation
This was referenced Mar 10, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Currently
map
is defined like this:Unfortunately this
map
operation is not equivalent with aflatMap(f.andThen(pure))
because by not suspending execution it can trigger stack overflow errors.As use-case, here's a toy
Iterant
implementation:The
filter
is pretty straightforward. Now lets build an already evaluated stream and filter it:Currently this
filter
operation blows with aStackOverflowException
.Why this is bad
Having users to remember which operations are safe and which operations can blow up in their face and in what contexts makes for a really bad user experience.
io.map(f)
should be equivalent withio.flatMap(x => pure(f(x)))
in all contexts, safety comes before performance.Also
monix.tail.Iterant
is a real example shipping in Monix 3.0 which is generic overF[_]
data types, making use ofcats.effect.Sync
.So I'd like a test for this to be in
SyncLaws
.The text was updated successfully, but these errors were encountered: