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

Using singleton on variables #558

Open
grncdr opened this issue Dec 31, 2020 · 1 comment
Open

Using singleton on variables #558

grncdr opened this issue Dec 31, 2020 · 1 comment

Comments

@grncdr
Copy link

grncdr commented Dec 31, 2020

It would be useful to be able to apply singleton to type variables as well as concrete types. As a motivating example consider this simple event bus:

interface _Subscriber[E]
  def call: (E event) -> void
end

class EventBus
  def subscribe: [E] (_Subscriber[E] subscriber, to: singleton(E)) -> void
  def dispatch: (untyped event) -> void
end

Here I want to specify that EventBus#subscribe expects the subscriber to handle events of the type given as the to: argument.

@mikhliuk-k
Copy link

I faced such problem too

For example, in my case I would like to do smth like:

class Builder
  def self.build: [C] (singleton(C) class) -> Array[C]
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants