Skip to content

Lower-level primitives for working with subscriptions #82

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
Jul 9, 2024
Merged

Conversation

fsoikin
Copy link
Contributor

@fsoikin fsoikin commented Jul 8, 2024

Some lower-level primitives to support less trivial subscription-related code in https://github.com/collegevine/app/pull/18834

@fsoikin fsoikin requested review from gasi, mcordova47 and a team July 9, 2024 15:47
Copy link
Contributor

@gasi gasi left a comment

Choose a reason for hiding this comment

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

LGTM 👍

TIL: You added subscriptions to Elmish


-- | Given a `Maybe`-producing subscription, creates a new subscription that
-- | filters out `Nothing` values and fires only on receiving `Just`.
hush :: ∀ m a. Subscription m (Maybe a) -> Subscription m a
Copy link
Contributor

Choose a reason for hiding this comment

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

FYI, the existing hush is Either a b -> Maybe b: https://pursuit.purescript.org/packages/purescript-either/6.1.0/docs/Data.Either#v:hush

How about compact (from Ruby) or something similar?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I know the existing hush, that's why I named it this way. I don't envision this function being used in most regular consumer code, only in special cases, and in those cases I intend it to be used qualified as in Subscription.hush.

Copy link
Contributor

@gasi gasi Jul 9, 2024

Choose a reason for hiding this comment

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

What about catMaybes as it nicely follows the existing signature of Array (Maybe a) -> Array a?

https://pursuit.purescript.org/packages/purescript-arrays/7.3.0/docs/Data.Array#v:catMaybes

Copy link
Contributor

Choose a reason for hiding this comment

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

FYI, late to the party, but looks like there is actually a Compactable typeclass that has exactly this shape:

class Compactable f where
  compact :: forall a.
    f (Maybe a) -> f a

Copy link
Contributor

Choose a reason for hiding this comment

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

@mcordova47 Nice find!

To be compactable alone, no laws must be satisfied other than the type signature.

😂

@fsoikin fsoikin merged commit 40253e1 into master Jul 9, 2024
4 checks passed
@fsoikin fsoikin deleted the quasi-bind branch July 9, 2024 15:52
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