Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Idea: the DU source-generator automatically writes the dispatching of the Match. #779

Open
FreeApophis opened this issue Jan 25, 2024 · 0 comments
Labels
area: DiscriminatedUnion Issues for Funcky.DiscriminateUnion to discuss There are open points which need to be discussed

Comments

@FreeApophis
Copy link
Member

I often rely on polymorphic overloads of the same method to handle DU cases indivdually:

Ideally I would have some syntax like this:

shape.Dipatch(Canvas.Draw);

This is obviously not possible, usually I write code like this: I write a public function which is delegating to individual overloads of the same Methodgroup. This is similar to the accept method in the visitor pattern:

public static Task<Image> Draw(Shape shape)
        => shape.Match(triangle: Draw, rectangle: Draw, polygon: Draw);

Source Generator:

[DispatchToMethodGroup] // name to discuss...
public partial static Task<Image> Draw(Shape shape)

DispatchToMethodGroup could take a parameter name optionally.

[DispatchToMethodGroup(nameof(Canvas.DrawInternal))]
public partial static Task<Image> Draw(Shape shape)
@FreeApophis FreeApophis added to discuss There are open points which need to be discussed area: DiscriminatedUnion Issues for Funcky.DiscriminateUnion labels Jan 25, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
area: DiscriminatedUnion Issues for Funcky.DiscriminateUnion to discuss There are open points which need to be discussed
Projects
None yet
Development

No branches or pull requests

1 participant