Class CollectionViewExtensionMethods
- Namespace
- SodaFlow.Collections
- Assembly
- SodaFlow.Collections.dll
The C# surface of the view chain of a collection. Filter,
SortBy, and Take accept an
ReactiveCollection<TKey, TIdentity, TState> and return one, as
Where takes an IEnumerable and returns one.
[PublicAPI]
public static class CollectionViewExtensionMethods
- Inheritance
-
CollectionViewExtensionMethods
- Inherited Members
Remarks
The stages make a chain. Each stage reads the ordered keys of the stage above it and makes its own ordered keys, thus the sequence in the code is the sequence of the operations. The root collection keeps its items in the sequence of their arrival, and this code builds the order of a stage only at the first read of it.
Know these three costs before you write a chain. First, a change to a
predicate tests each key of the upstream again, and reports the keys
that entered and left as inserts and removals, not as a reset. The
stages below adjust and do not build again. When more keys move than a
list of them is worth, the filter builds again at a cost of
O(m log m) and reports a reset, and so does each stage below it.
A change to a limit, an offset, or an order always builds that stage
and each stage below it again and reports a reset. Put a Calm stage
above a criteria from a keystroke.
Second,
Take<TKey, TIdentity, TState>(ReactiveCollection<TKey, TIdentity, TState>, int)
and
Slice<TKey, TIdentity, TState>(ReactiveCollection<TKey, TIdentity, TState>, int, int)
, of which the first is the condition with an offset of zero, compare
their previous window against their new window and do not change the
operations from above. Thus, a change of order in the window comes as
removals and adds, and not as moves. For the same cause there is no
Skip: that step has a low cost because the window has a limit at
each end. Third, a Filter after a Take filters the window
and thus gives limit items or fewer. Write the Filter
first for a different result.
Methods
- FilterByIdentity<TKey, TIdentity, TState>(ReactiveCollection<TKey, TIdentity, TState>, Cell<Func<TIdentity, bool>>)
Narrows the view with a predicate on the identity of each item that can change. Each change to the predicate tests each item of the upstream again, and reports the keys that entered and left as inserts and removals, not as a reset.
- FilterByIdentity<TKey, TIdentity, TState>(ReactiveCollection<TKey, TIdentity, TState>, Func<TIdentity, bool>)
Narrows the view with a predicate on the immutable part of each item, which is its identity. A state edit cannot change that part.
- FilterByIdentity<TKey, TIdentity, TState, TCriteria>(ReactiveCollection<TKey, TIdentity, TState>, Cell<TCriteria>, Func<TCriteria, TIdentity, bool>)
Narrows the view with a predicate on the identity of each item from a different source, such as a search box or a toggle. Each change to the criteria tests each item of the upstream again, thus a criteria from a keystroke needs a Calm stage above this one.
- Filter<TKey, TIdentity, TState>(ReactiveCollection<TKey, TIdentity, TState>, Cell<Func<TIdentity, TState, bool>>)
Narrows the view with a predicate that can change. Each change to the predicate tests each item of the upstream again, and reports the keys that entered and left as inserts and removals, not as a reset.
- Filter<TKey, TIdentity, TState>(ReactiveCollection<TKey, TIdentity, TState>, Func<TIdentity, TState, bool>)
Narrows the view and keeps the upstream order.
- Filter<TKey, TIdentity, TState, TCriteria>(ReactiveCollection<TKey, TIdentity, TState>, Cell<TCriteria>, Func<TCriteria, TIdentity, TState, bool>)
Narrows the view with a predicate from a different source, such as a search box or a toggle. Each change to the criteria tests each item of the upstream again, thus a criteria from a keystroke needs a Calm stage above this one.
- Map<TKey, TIdentity, TState, TResult>(ReactiveCollection<TKey, TIdentity, TState>, Func<TKey, TResult>, int, Action<TResult>?)
One object for each key, in the order of this collection, thus a list can bind to a stable object.
- Slice<TKey, TIdentity, TState>(ReactiveCollection<TKey, TIdentity, TState>, Cell<int>, Cell<int>)
A page of the upstream where each end can change. Send a new offset to move to a different page.
- Slice<TKey, TIdentity, TState>(ReactiveCollection<TKey, TIdentity, TState>, int, int)
limitkeys of the upstream that start atoffset, which are a page of the order and the filter above this stage.
- SortByArrival<TKey, TIdentity, TState>(ReactiveCollection<TKey, TIdentity, TState>)
Reorders by arrival, which is the order of the collection. It is available above each stage.
- SortByDescending<TKey, TIdentity, TState, TSortKey>(ReactiveCollection<TKey, TIdentity, TState>, Func<TIdentity, TState, TSortKey>)
Reorders the view, descending, by a value projected from each item.
- SortByIdentityDescending<TKey, TIdentity, TState, TSortKey>(ReactiveCollection<TKey, TIdentity, TState>, Func<TIdentity, TSortKey>)
Reorders the view, descending, by a value from the identity of each item.
- SortByIdentity<TKey, TIdentity, TState, TSortKey>(ReactiveCollection<TKey, TIdentity, TState>, Func<TIdentity, TSortKey>)
Reorders the view by a value from the immutable part of each item, which is its identity. A state edit cannot change that part.
- SortByIdentity<TKey, TIdentity, TState, TSortKey>(ReactiveCollection<TKey, TIdentity, TState>, Func<TIdentity, TSortKey>, IComparer<TSortKey>, IComparer<TKey>, bool)
Reorders the view by a value from the identity of each item, with explicit comparers.
- SortByKeyDescending<TKey, TIdentity, TState>(ReactiveCollection<TKey, TIdentity, TState>)
Reorders by key, descending, over any stage.
- SortByKey<TKey, TIdentity, TState>(ReactiveCollection<TKey, TIdentity, TState>)
Reorders by key, over any stage.
- SortByKey<TKey, TIdentity, TState>(ReactiveCollection<TKey, TIdentity, TState>, IComparer<TKey>, bool)
Reorders by key, over any stage, with an explicit comparer.
- SortBy<TKey, TIdentity, TState>(ReactiveCollection<TKey, TIdentity, TState>, Cell<KeyOrder<TKey, TIdentity, TState>>)
Reorders the view by whichever order the cell currently holds.
- SortBy<TKey, TIdentity, TState>(ReactiveCollection<TKey, TIdentity, TState>, KeyOrder<TKey, TIdentity, TState>)
Reorders the view by an order that does not change.
- SortBy<TKey, TIdentity, TState, TSortKey>(ReactiveCollection<TKey, TIdentity, TState>, Func<TIdentity, TState, TSortKey>)
Reorders the view by a value projected from each item.
- SortBy<TKey, TIdentity, TState, TSortKey>(ReactiveCollection<TKey, TIdentity, TState>, Func<TIdentity, TState, TSortKey>, IComparer<TSortKey>, IComparer<TKey>, bool)
Reorders the view.
TSortKeystays a generic parameter to the comparer, thus this code keeps and compares each sort value as its own type and never boxes it.
- Take<TKey, TIdentity, TState>(ReactiveCollection<TKey, TIdentity, TState>, Cell<int>)
The first keys of the upstream, and that count can change.
- Take<TKey, TIdentity, TState>(ReactiveCollection<TKey, TIdentity, TState>, int)
The first
limitkeys of the upstream, which are the highest keys of the order and the filter above this stage.