Off the cuff I can't quote see how that eliminates my problem which I currently 
mostly see in `Operator` storing a Ref to a parent-instance which may have an 
unknown amount of generic params. With turning callbacks into closures I can 
eliminate some of the types, but that not all of them as I'd need.

The key here is that Observers may get called N times, every time a new value 
gets pushed through the pipeline. So I'm not executing the closure just once or 
multiple times with the same value, I execute it multiple times with different 
values each time.

So I could only imagine this in this kind of construct:
    
    
    type Observer[T] = ref object
      value: T
      subscription: proc() {.closure.}
    
    proc newObserver[T](subscription: proc(value: T)): Observer[T] =
      let obs = Observer[T](value: default(T))
      proc subscriptionClosure() {.closure.} =
        subscription(obs.value)
      
      obs.subscription = subscriptionClosure
      return obs
    
    let obs = newObserver(proc(x: int) = echo "Value is: ", x)
    obs.subscription() # value is: 0
    obs.value = 4
    obs.subscription() # value is: 4
    
    
    Run

Which gets rid of the type in the callback I need to call, but now I need an 
external value to manipulate for the closure I need to call, so I still have a 
T.

Reply via email to