-
Notifications
You must be signed in to change notification settings - Fork 102
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
Conversation
033bbe8
to
f62e294
Compare
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.
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) |
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.
Just curious, any reason to use sometimes fn
, sometimes a
and sometimesm
for the variable to test?
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.
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.
src/Async/README.md
Outdated
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 |
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.
Small typo: ways instead of way
src/Async/README.md
Outdated
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 |
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.
Small typo: ways instead of way
src/Async/README.md
Outdated
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`. |
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.
Maybe explaining why rej
and res
are reversed should be nice to have. I am curious too 😄
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.
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.
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.
That said I think I can throw something in like:
... reversed in an
Async
to match the order in whichAsync
is parameterized.
Do you think that could provide some hint to why?
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.
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 |
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.
Any reason to not use apply
instead of ap
? IMHO ap
can be confused. (Probably this is not related to that PR)
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.
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
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.
Yeah, was thinking something about the apply
method, but since was an object I asked it. But yeah, now make sense. 👍
src/Async/README.md
Outdated
|
||
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 |
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.
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.
src/Async/README.md
Outdated
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 |
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.
lastToAsync
instead of firstToAsync
@evilsoft do you think is better to put everything in one single commit? |
@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), Once I PR it publicly it though, I never amend. That way:
But I still rebase if there are merge conflicts during the review cycle. |
At the SAME time
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
Monoid
s 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 theMaybe
docs which really should have ALSO been its own PR.