Thank you!
this does work:
>
> type
> Data*[T] = object
> contents: T
> subscribers: seq[proc(d: T)]
>
> proc createData*[T](t: typedesc[T], c: T): Data[T] =
> result = Data[T]()
> result.contents = c
> result.subscribers = @[]
>
> pr
proc addSubscriber*[T](d: var Data[T], cb: proc(d:T)) =
d.subscribers.add(cb)
Run
A typo `T` for `Data[T]`, and `var` needed for `add`.
Thankyou for your reply @mratsim
I tried the following:
type
Data*[T] = object
id: string
contents: T
subscribers: seq[proc(d: T)]
proc addSubscriber*[T](d: T, cb: proc(d:T)) =
d.subscribers.add(cb)
proc c
Yes you can, see this for example:
[https://github.com/mratsim/nim-rmad/blob/master/src/autograd.nim#L46-L57](https://github.com/mratsim/nim-rmad/blob/master/src/autograd.nim#L46-L57)
Note that the proc arity (number of arguments) is part of the type, as is its
calling convention (pointer/{.nimc
is there a way to have a collection (seq or better: Tables) of procs with
generic types?