public static void RemoveAll <T, T2>(this IReactiveList <T> list, Predicate <T2> predicate) where T2 : T { if (list == null) { throw new ArgumentNullException(nameof(list)); } if (predicate == null) { throw new ArgumentNullException(nameof(predicate)); } list.RemoveAll(list.Where(x => predicate((T2)x)).ToArray()); }
/* public static void RemoveAllLocked<T, T2>(this ReactiveList<T> list, IEnumerable<T2> other) where T2 : T * { * if (list == null) throw new ArgumentNullException(nameof(list)); * if (other == null) throw new ArgumentNullException(nameof(other)); * lock (list) * list.RemoveAll(other); * }*/ public static void RemoveAllLocked <T>(this IReactiveList <T> list, Predicate <T> predicate) { if (list == null) { throw new ArgumentNullException(nameof(list)); } if (predicate == null) { throw new ArgumentNullException(nameof(predicate)); } lock (list) list.RemoveAll(list.Where(x => predicate(x)).ToArray()); }
void SetupCollectionItems <T>(IReactiveList <T> src, IReactiveList <IHierarchicalLibraryItem> dst, Func <T, bool> predicate = null) where T : Collection { lock (src) { var srcF = predicate == null ? src : src.Where(predicate); lock (dst) dst.AddRange(srcF.Select(CreateCustomModSet)); _disposables.Add(src.TrackChanges( x => dst.AddLocked(CreateCustomModSet(x)), x => { lock (CollectionsGroup.Children) dst.RemoveLocked(GetCollection(x)); }, reset => { lock (dst) { lock (CollectionsGroup.Children) dst.RemoveAll(GetCollections().ToArray()); dst.AddRange(reset.Select(CreateCustomModSet)); } }, predicate)); } }
public static CompositeDisposable TrackChangesOnUiThread <T>(this IReactiveList <T> list, Action <T> add, Action <T> remove, Action <IEnumerable <T> > reset, Func <T, bool> filter = null) { if (list == null) { throw new ArgumentNullException(nameof(list)); } var disposables = new CompositeDisposable(); if (add != null) { var o = list.ItemsAdded; if (filter != null) { o = o.Where(filter); } disposables.Add(o.ObserveOn(RxApp.MainThreadScheduler) .Subscribe(add)); } if (remove != null) { var o = list.ItemsRemoved; if (filter != null) { o = o.Where(filter); } disposables.Add(o.ObserveOn(RxApp.MainThreadScheduler) .Subscribe(remove)); } if (reset != null) { disposables.Add(list.ShouldReset .ObserveOn(RxApp.MainThreadScheduler) .Subscribe(x => reset(filter == null ? list.ToArray() : list.Where(filter).ToArray()))); } return(disposables); }