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

Fix: at now curried + some addition to documentation #677

Merged
merged 6 commits into from
Mar 8, 2024

Conversation

semmel
Copy link
Contributor

@semmel semmel commented Mar 7, 2024

fixes #676

and docs newStream and adds PACKAGES.md to Readme.md

Just a quickly jotted down PR.

Happy to change/correct anything.
:-)

@@ -6,6 +6,7 @@
| [hold](https://github.com/mostjs/hold) | Deliver the most recently seen event to new observers
| [create](https://github.com/mostjs/create) | Imperatively push events into a Stream
| [dom-event](https://github.com/mostjs/dom-event) | Streamlined DOM Events
| [adapter](https://github.com/mostjs/adapter) | Imperatively put events into mostjs streams
Copy link
Member

Choose a reason for hiding this comment

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

👍 Thanks

docs/api.rst Outdated
)
.finally(() => sink.end(ct(scheduler));

return { dispose: () => undefined };
Copy link
Member

Choose a reason for hiding this comment

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

It'd be great to show a real disposable here, e.g. one that prevents the call to sink.event/error/end above.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have changed the example using setTimeout now with dispose.

Comment on lines 19 to 20
<A>(time: Time, value: A): Stream<A>
<A>(time: Time): (value: A) => Stream<A>
Copy link
Member

Choose a reason for hiding this comment

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

Oh jeez, I'm sorry. It didn't occur to me in #676 that this might be a breaking change for JavaScript users. I just noticed it now that I see these type signatures.

In the non-curried version, at's TS type requires the second parameter, i.e. the value, but a JS caller could omit it, e.g. at(time), and it would return a Stream.

By currying it, the JS behavior will change: instead of at(time) returning Stream, it will return a function (value) => Stream 😕

We'd need to release it as 2.0.0 to signal the breaking change. It's not a blocker, though, since I don't really care about the "marketing value" of version numbers. I figured it was worth calling out, though.

That might be reason enough to separate this into 2 PRs: one for the non-breaking changes, and one for the breaking change to at.

Thoughts on all of that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok I understand, I too missed that this is a breaking change.

I think, currying at is a too small change that it alone not justifies releasing a "2.0".
I reverted that commit, so that this PR now only deals with the non-breaking changes to the documentation.

I could author another PR for at, but rather I'd somehow bookmark the commit as "2.0-planned" to include later if the real need for a version "2.0" should arise.

Perhaps you could mark the issue #676 with a label like "2.0"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've updated the signature for at in the documentation to reflect it's signature as uncurried binary and unary function.

Copy link
Member

Choose a reason for hiding this comment

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

Perhaps you could mark the issue #676 with a label like "2.0"?

Great idea! Done.

@@ -12,4 +12,11 @@ describe('at', () => {
return collectEventsFor(t, at(t, expected))
.then(eq([{ time: t, value: expected }]))
})
it('is auto-curried', function () {
Copy link
Member

Choose a reason for hiding this comment

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

It's ok not to test this. The types already guarantee it. For example, here's the type error we'd get if we wrote this same code without at being curried:

Screen Shot 2024-03-07 at 6 56 02 PM

Copy link
Member

@briancavalier briancavalier left a comment

Choose a reason for hiding this comment

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

Looks good. Thank you!

@@ -286,7 +286,8 @@ at

.. code-block:: haskell

at :: Time -> a -> Stream a
at :: (Time, a) -> Stream a
at :: Time -> Stream void
Copy link
Member

Choose a reason for hiding this comment

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

Unfortunately, the second signature is only valid for JavaScript. The TS types currently prevent calling at with just 1 argument.

Maybe we can keep only the first signature, and add a note for JavaScript users?

Suggested change
at :: Time -> Stream void

sink.end(ct(scheduler));
};
const timer = setTimeout(publishVal, delay, value);
return { dispose: () => { clearTimeout(timer); } };
Copy link
Member

Choose a reason for hiding this comment

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

👍

@briancavalier briancavalier merged commit 015c0a2 into mostjs:master Mar 8, 2024
0 of 2 checks passed
@semmel semmel deleted the curry-at branch March 11, 2024 10:51
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.

Is there a reason why at(time, val) is not curried?
2 participants