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 Async Documentation #204

Merged
merged 4 commits into from
Feb 14, 2018
Merged

Add Async Documentation #204

merged 4 commits into from
Feb 14, 2018

Conversation

evilsoft
Copy link
Owner

At the SAME time

image

This PR is mostly centered around adding the Async docs to address this issue.

Like many of the other docs added, I took the time to address some legacy error tests that have been providing false positives. Will need to circle back on some of the spec updates for some of the Monoids that have already been documented. TBH I should have done a separate PR to address the specs, and WILL do so in the future to keep review time down. Also corrected a spelling error in the Maybe docs which really should have ALSO been its own PR.

@coveralls
Copy link

coveralls commented Feb 13, 2018

Coverage Status

Coverage remained the same at 100.0% when pulling 7981022 on async-docs-specs into 8fba9fd on master.

Copy link
Collaborator

@HenriqueLimas HenriqueLimas left a comment

Choose a reason for hiding this comment

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

These docs are amazing. I found some little typos and add some questions, maybe not related to that PR.

@@ -118,36 +119,37 @@ test('Async Resolved', t => {
})

test('Async fromPromise', t => {
const resProm = x => new Promise((res) => res(x))
const resProm = x => new Promise(res => res(x))

t.ok(isFunction(Async.fromPromise), 'is a function')
t.ok(isFunction(Async.fromPromise(resProm)), 'returns a function')

const fn = bindFunc(Async.fromPromise)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just curious, any reason to use sometimes fn, sometimes a and sometimesm for the variable to test?

Copy link
Owner Author

Choose a reason for hiding this comment

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

Typically I use fn for a function, you will see that mostly with error testing functions.
Now a and m should probably, eventually be replaced with just m...I use m to represent a given ADT.

difference, the arguments used in the function that is passed to the `Promise`
constructor are reversed in an `Async`.

There are many way to represent asynchronous operations in JavaScript, and as
Copy link
Collaborator

Choose a reason for hiding this comment

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

Small typo: ways instead of way

difference, the arguments used in the function that is passed to the `Promise`
constructor are reversed in an `Async`.

There are many way to represent asynchronous operations in JavaScript, and as
Copy link
Collaborator

Choose a reason for hiding this comment

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

Small typo: ways instead of way

Depending on your needs, an `Async` can be constructed in a variety of ways. The
typical closely resembles how a `Promise` is constructed with one major
difference, the arguments used in the function that is passed to the `Promise`
constructor are reversed in an `Async`.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe explaining why rej and res are reversed should be nice to have. I am curious too 😄

Copy link
Owner Author

@evilsoft evilsoft Feb 13, 2018

Choose a reason for hiding this comment

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

It may not be the right place to explain it in the docs. But I can do it here: So it is typical and easier to follow when the far right parameter of a type is the portion that a covariant functor works with (map). So because of this, the Resolved is the parameter that works with map. So to keep everything lined up and easier to follow, the arguments to the functions are in the same order.

Copy link
Owner Author

Choose a reason for hiding this comment

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

That said I think I can throw something in like:

... reversed in an Async to match the order in which Async is parameterized.

Do you think that could provide some hint to why?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, it can help IMHO, but it's your call here.

Async e (a -> b) ~> Async e a -> Async e b
```

Short for apply, `ap` is used to apply an `Async` instance containing a value
Copy link
Collaborator

Choose a reason for hiding this comment

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

Any reason to not use apply instead of ap? IMHO ap can be confused. (Probably this is not related to that PR)

Copy link
Owner Author

Choose a reason for hiding this comment

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

ap is defined by Fantasy-Land. Say we want to have "static" functions on our constructor (we do not do this in crocks, but some libs do), apply would override the Function.prototype.apply. Even though we do not implement the ap spec as defined by Fantasy-Land, it makes sense to still keep the naming 🌽sistant

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah, was thinking something about the apply method, but since was an object I asked it. But yeah, now make sense. 👍


The second signature is used when any cleanup needs to be performed after a
given `Async` is cancelled by having the function returned from `fork` called.
The first to arguments to the signature are the same as the more common
Copy link
Collaborator

Choose a reason for hiding this comment

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

Some little typos here (in bold):
The first two arguments to the signature are the same as the more common
signature described above but takes an additional function that can be used
for "clean up" after cancellation.

argument. This value will be wrapped in a resulting `Rejected` instance, in the
case of empty.

Like all `crocks` transformation functions, `firstToAsync` has (2) possible
Copy link
Collaborator

Choose a reason for hiding this comment

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

lastToAsync instead of firstToAsync

@HenriqueLimas
Copy link
Collaborator

@evilsoft do you think is better to put everything in one single commit?

@evilsoft
Copy link
Owner Author

evilsoft commented Feb 13, 2018

@HenriqueLimas Not really, what I should have done, to make it easier to review, is put the Specs in its own commit (well really its own PR),
But until a PR is made, I usually keep it to one. This makes rebasing and other branch management tasks easier.

Once I PR it publicly it though, I never amend. That way:

  • Reviewer never has to kill their local before pulling down a force push
  • Easier to review a commit to see what was changed after feedback was addressed.
  • it gives a nice breadcrumb trail on changes from PR feedback.

But I still rebase if there are merge conflicts during the review cycle.

@evilsoft
Copy link
Owner Author

Okay going to call this done. Merging.
image

@evilsoft evilsoft merged commit 85d549a into master Feb 14, 2018
@evilsoft evilsoft deleted the async-docs-specs branch February 14, 2018 03:33
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.

3 participants