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

Bracket docs #1134

Merged
merged 9 commits into from
Nov 17, 2018
Merged

Bracket docs #1134

merged 9 commits into from
Nov 17, 2018

Conversation

JorgeCastilloPrz
Copy link
Member

fixes #1129

@JorgeCastilloPrz JorgeCastilloPrz added this to the Q1 2019 milestone Nov 16, 2018
@JorgeCastilloPrz JorgeCastilloPrz self-assigned this Nov 16, 2018
@codecov
Copy link

codecov bot commented Nov 16, 2018

Codecov Report

Merging #1134 into master will decrease coverage by <.01%.
The diff coverage is n/a.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #1134      +/-   ##
============================================
- Coverage     42.78%   42.77%   -0.01%     
  Complexity      813      813              
============================================
  Files           400      400              
  Lines         11000    11000              
  Branches       1256     1256              
============================================
- Hits           4706     4705       -1     
  Misses         5927     5927              
- Partials        367      368       +1
Impacted Files Coverage Δ Complexity Δ
.../arrow-effects/src/main/kotlin/arrow/effects/IO.kt 79.74% <ø> (ø) 16 <0> (ø) ⬇️
...outines/src/main/kotlin/arrow/effects/DeferredK.kt 57.35% <0%> (-1.48%) 6% <0%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update db968d4...9ae4186. Read the comment docs.

Copy link
Member

@nomisRev nomisRev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏

```kotlin:ank
import arrow.effects.IO

openFile("data.json").bracket(release = { closeFile(it) }) { file ->
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: use named lambdas for both functions

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed now.

Copy link
Member

@raulraja raulraja left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Docs look great!. I would love to see the code example being executables like the AQL ones.


The `Bracket` Type class abstracts the ability to safely **acquire**, **use**, and then **release** a resource.

Essentially, it could be considered the functional programming equivalent to the well known imperative
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something worth noticing here is that Bracket, unlike try/catch/finally works in all contexts when powered with an async capable data type such as Deferred, Observable or IO. Since it targets Kinds and not just the current thread environment like try/catch/finallydo, it can be relied upon with the same semantics in synchronous and async computations.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. I've just added an additional example clarifying that and showcasing a polymorphic program using Bracket<F, Throwable> as a constraint, and running over the 3 mentioned data types.

It ensures that the acquired resource is released at the end after using it, **even if the using action throws an error**.
That ensures that no errors are swallowed.

Another key point of `Bracket` would be the ability to abstract over whether the resource is going to be used
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this is in line with my point above but it does not spread the gospel comparing it to try/catch/finally and showing how it's a superior abstraction

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, explained above.


`fun <A, B> Kind<F, A>.bracketCase(release: (A, ExitCase<Throwable>) -> Kind<F, Unit>, use: (A) -> Kind<F, B>): Kind<F, B>`

```kotlin:ank
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make all these snippets executable like in the AQL docs, please? These are API examples more than a tutorial and as a user I'd like to play with it right in the browser

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I'll take a look tomorrow. Leaving now!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@raulraja is there a policy about which snippets should be executable? Should we aim for as much as possible executable snippets?

@JorgeCastilloPrz
Copy link
Member Author

JorgeCastilloPrz commented Nov 17, 2018

@raulraja tried to do port everything to be executable but Bracket was included in 0.8.1 and try arrow is still not pointing to that version. Would it be okay to merge the docs as they are and iterate on that once try arrow gets upgraded?

cc @dominv

@raulraja
Copy link
Member

Yes but this should work because try arrow is supposed to pull the latest snapshot out of master. Which means that once you run the snippets in the live site they will work since try arrow is supposed to automatically deploy the latest snapshot

@JorgeCastilloPrz JorgeCastilloPrz merged commit 3d7d4ce into master Nov 17, 2018
@JorgeCastilloPrz JorgeCastilloPrz deleted the 1129-jc-bracket-docs branch November 17, 2018 15:48
@calvellido
Copy link
Member

I think the problem is not related with the Arrow version, but with some changes needed to be made on the compiler config as the error some of those snippets are facing is the following:

Exception in thread "main" java.lang.IllegalStateException: No BuiltInsLoader implementation was found. Please ensure that the META-INF/services/ is not stripped from your application and that the Java virtual machine is not running under a security manager

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.

[Arrow] Bracket docs
4 participants