Skip to content

Fix IOFrame usage in IOBracket #1258

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

Merged
merged 1 commit into from
Jan 20, 2019
Merged

Fix IOFrame usage in IOBracket #1258

merged 1 commit into from
Jan 20, 2019

Conversation

nomisRev
Copy link
Member

@nomisRev nomisRev commented Jan 20, 2019

IOFrame was not correctly called unless manually wrapped in IO.Bind. It did not run using flatMap like Cats-effect's IO because IO.RaiseError is overridden to short-circuit flatMap like this override fun <B> flatMap(f: (Nothing) -> IOOf<B>): IO<B> = this

To leave the overridden function as explicit as it currently is I opted to elaborate in the IOFrame docs how to properly use it. Also, I added a test for this and changed the usage in IOBracket.

Do we want to keep it like this or shall we override IO.RaiseError#flatMap as follows to prevent similar bugs by miss-use in the future?

override fun <B> flatMap(f: (Nothing) -> IOOf<B>): IO<B> =
      if (f is IOFrame) Bind(this, f as (Nothing) -> IO<B>) else this

@pakoito pakoito merged commit 632a41e into master Jan 20, 2019
@pakoito pakoito deleted the simon-fix-io-bracket branch January 20, 2019 14:31
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.

2 participants