/// <summary> /// Returns a observable of cache changes preceeded with the initital cache state /// </summary> /// <param name="predicate">The result will be filtered using the specfied predicate.</param> /// <returns></returns> public IObservable <IChangeSet <TObject, TKey> > Connect(Func <TObject, bool> predicate = null) { return(Observable.Create <IChangeSet <TObject, TKey> > ( observer => { if (predicate == null) { return Observable.Return(_innerCache.AsInitialUpdates()) .Concat(_changes) .SubscribeSafe(observer); } var updater = new FilteredUpdater <TObject, TKey>(new ChangeAwareCache <TObject, TKey>(), predicate); var filtered = updater.Update(_innerCache.AsInitialUpdates(predicate)); if (filtered.Count != 0) { observer.OnNext(filtered); } return _changes .Select(updater.Update) .NotEmpty() .SubscribeSafe(observer); })); }