rbs icon indicating copy to clipboard operation
rbs copied to clipboard

Using `singleton` on variables

Open grncdr opened this issue 5 years ago • 1 comments

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.

grncdr avatar Dec 31 '20 13:12 grncdr

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

mikhliuk-k avatar Jul 12 '23 22:07 mikhliuk-k