Skip to content

[feat]: add primary associated types to Workflow protocol #181

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
Jan 19, 2023

Conversation

jamieQ
Copy link
Contributor

@jamieQ jamieQ commented Jan 19, 2023

Issue

  • Workflow doesn't yet expose primary associated types, which makes some forms of type-erasure less useful or impossible

Description

  • adds Rendering and Output as the primary associated types of the Workflow protocol

Checklist

  • Unit Tests
  • UI Tests
  • Snapshot Tests (iOS only)
  • I have made corresponding changes to the documentation

/// Defines the state that is managed by this workflow.
associatedtype State
#if swift(>=5.7)
public protocol Workflow<Rendering, Output>: AnyWorkflowConvertible {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

for the time being, decided to just make this change on Workflow itself, as i believe that is by far the most useful change. if there are other compelling additions we could add them in the future.

with this change, we can now leverage the following forms of type erasure:

func boxedAnyWorkflow() -> AnyWorkflow<Rendering, Output> {
  MyWorkflow().asAnyWorkflow()
}

func existentialAnyWorkflow() -> any Workflow<Rendering, Output> {
  if someCondition {
    return MyWorkflow()
  } else {
    return MyOtherWorkflow()
  }
}

func opaqueWorkflow() -> some Workflow<Rendering, Output> {
  MyWorkflow()
}

@jamieQ jamieQ marked this pull request as ready for review January 19, 2023 03:24
@jamieQ jamieQ requested a review from a team as a code owner January 19, 2023 03:24
Copy link
Collaborator

@mjohnson12 mjohnson12 left a comment

Choose a reason for hiding this comment

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

Nice addition.

@jamieQ jamieQ merged commit dfa2ac1 into main Jan 19, 2023
@jamieQ jamieQ deleted the jquadri/add-pats branch January 19, 2023 16:34
jamieQ added a commit that referenced this pull request Feb 6, 2023
* main:
  [fix]: use weak reference to internal sinks when vending to clients (#189)
  [feat]: add primary associated types to more protocols (#188)
  [chore]: pre major version bump cleanup (#187)
  [chore]: bump minimum deployment & swift versions (#186)
  Abstract ViewEnvironment to shared framework (#185)
  Bump activesupport from 6.1.4.4 to 6.1.7.1 (#183)
  [feat]: add primary associated types to `Workflow` protocol (#181)
  [chore]: update swiftformat ifdef indent rule to no-indent (#182)
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.

2 participants