0no-co / wonka

🎩 A tiny but capable push & pull stream library for TypeScript and Flow
MIT License
709 stars 29 forks source link

Buffer operator #26

Closed isker closed 5 years ago

isker commented 5 years ago

Hi! I'm trying to implement request batching in urql. I'm not at all familiar with rxjs-style APIs, but as far as I can tell, this requires a buffer and/or bufferTime operator in wonka. (I'm assuming that you can define bufferTime in terms of buffer.)

If I'm right about all of that, is this an enhancement you're open to?

(For now I've implemented one local to my project in JS. That was somewhat painful due to the generated JS for some of the types not being very easy to use. Flow is not impressed with attempts to produce objects satisfying this type:

export type Signal<A> =
  | ({
      tag: 0
    } & [(talkback: Talkback) => void])
  | ({
      tag: 1
    } & [A])
  | 0;

)

parkerziegler commented 5 years ago

@isker I definitely think wonka could benefit from a buffer operator. Even bufferCount, bufferTime, and bufferWhen could be useful. I'm not sure reasonably when either @kitten or I will be able to get to this, but I think it'd be a good feature if you want to take a stab at getting it going. You could also paste your JS impl here if you're comfortable and I can try to move it to work in the callbag style in Reason.