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

BailHook default handler #33

Merged
merged 12 commits into from
Jun 2, 2023
Merged

Conversation

brocollie08
Copy link
Contributor

@brocollie08 brocollie08 commented May 31, 2023

What Changed

Added a default handler to SyncBailHook call to automatically handle non-bail cases

Why

Provide a default behaviour for when all the taps continue

Todo:

  • Add tests
  • Add docs
  • Add release notes

Release Notes

Allows for SyncBailHook to call with a default handler for when the taps do not bail and return nothing

📦 Published PR as canary version: 0.14.1-canary.33.352-SNAPSHOT

}
}

default?.invoke(p1)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this'd be return default?.invoke(p1)

@@ -6,16 +6,18 @@ public sealed class BailResult<T> {
public class Continue<T> : BailResult<T>()
}

public abstract class SyncBailHook<F : Function<BailResult<R>>, R> : SyncBaseHook<F>("SyncBailHook") {
protected fun call(invokeWithContext: (F, HookContext) -> BailResult<R>): R? {
public abstract class SyncBailHook<T, F : (HookContext, T) -> BailResult<R>, R> : SyncBaseHook<F>("SyncBailHook") {
Copy link
Collaborator

Choose a reason for hiding this comment

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

We can't assume arity here. This is explicitly Function, because that type is arity-less. I'm not sure we need to change anything in the base definition.

public abstract class SyncBailHook<F : Function<BailResult<R>>, R> : SyncBaseHook<F>("SyncBailHook") {
protected fun call(invokeWithContext: (F, HookContext) -> BailResult<R>): R? {
public abstract class SyncBailHook<T, F : (HookContext, T) -> BailResult<R>, R> : SyncBaseHook<F>("SyncBailHook") {
protected fun call(invokeWithContext: (F, HookContext) -> BailResult<R>, default: ((T) -> Unit)? = null, p1: T): R? {
Copy link
Collaborator

Choose a reason for hiding this comment

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

The type of default would probably be F. If we don't want the return type to be bounded to BailResult, then we'd need to add another type param for the SyncBailHook to capture the type of the default F.

@brocollie08 brocollie08 marked this pull request as ready for review June 2, 2023 00:42
@sugarmanz sugarmanz added the minor Increment the minor version when merged label Jun 2, 2023
Co-authored-by: Jeremiah Zucker <zucker.jeremiah@gmail.com>
@sugarmanz sugarmanz added this pull request to the merge queue Jun 2, 2023
Merged via the queue into intuit:main with commit f434786 Jun 2, 2023
@sugarmanz
Copy link
Collaborator

🚀 PR was released in v0.15.0 🚀

@sugarmanz sugarmanz added the released This issue/pull request has been released. label Jun 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
minor Increment the minor version when merged released This issue/pull request has been released.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants