public static IStream <T> FirstOnly <T>(this IStream <T> stream) { return(new AnonymousStream <T>((Action <T> reaction, Priority p) => { SingleAssignmentDisposable disp = new SingleAssignmentDisposable(); disp.Disposable = stream.Listen(val => { reaction(val); disp.Dispose(); }, p); return disp; })); }
public static IEmptyStream FirstOnly(this IEmptyStream stream) { return(new AnonymousEmptyStream((Action reaction, Priority p) => { SingleAssignmentDisposable disp = new SingleAssignmentDisposable(); disp.Disposable = stream.Listen(() => { reaction(); disp.Dispose(); }, p); return disp; })); }
private static IOnceEmptyStream OnceEmptyStream(IEmptyStream stream) { return(new AnonymousEmptyStream((Action reaction, Priority p) => { SingleAssignmentDisposable disp = new SingleAssignmentDisposable(); disp.Disposable = stream.Listen(() => { reaction(); disp.Dispose(); }, p); return disp; })); }
static public IStream <T> Join <T>(this IStream <IStream <T> > stream) { return(new AnonymousStream <T>((Action <T> reaction, Priority p) => { SingleAssignmentDisposable mainDisposable = new SingleAssignmentDisposable(); SingleAssignmentDisposable inner = new SingleAssignmentDisposable(); ListDisposable group = new ListDisposable { mainDisposable, inner }; mainDisposable.Disposable = stream.Listen((IStream <T> innerStream) => { var newDisp = innerStream.Listen(val => { reaction(val); }, p); inner.Dispose(); inner.Disposable = newDisp; }, p); return group; })); }