[Feature]: Add TransformVirtual Extensions for IObservableList and IObservableCache
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
調査の方向性
Read the existing Transform operator and the IObservableList/IObservableCache interfaces, then inspect how Connect and Preview expose change sets. Implementations are shown for IObservableList, but the issue does not identify repository files or tests, and the cache behavior still needs working out. Done means both extensions expose virtual transformed views with the described access, subscription, and disposal behavior; add tests for list and cache behavior.
索引モデルが issue の本文から書いたものです。
説明
Describe the functionality desired 🐞
New extension methods TransformVirtual<TSource, TResult>(Func<TSource, TResult> transformFactory) for IObservableList<TSource> and IObservableCache<TSource, TKey> that create lightweight views of type IObservableList<TResult>/IObservableCache<TResult, TKey> without intermediate storage collection.
There's an implementation for IObservableList I created and used in my project:
public static class CollectionExtensions
{
extension<T>(IReadOnlyList<T> source)
{
public IReadOnlyList<TResult> TransformVirtual<TResult>(Func<T, TResult> transformFactory)
{
ArgumentNullException.ThrowIfNull(source);
ArgumentNullException.ThrowIfNull(transformFactory);
return new ReadOnlyListTransformVirtual<T, TResult>(source, transformFactory);
}
}
private sealed class ReadOnlyListTransformVirtual<TSource, TResult> : IReadOnlyList<TResult>
{
private readonly IReadOnlyList<TSource> _source;
private readonly Func<TSource, TResult> _transformFactory;
public ReadOnlyListTransformVirtual(IReadOnlyList<TSource> source, Func<TSource, TResult> transformFactory)
{
_source = source;
_transformFactory = transformFactory;
}
public TResult this[int index] => _transformFactory(_source[index]);
public int Count => _source.Count;
public IEnumerator<TResult> GetEnumerator() => _source.Select(x => _transformFactory(x)).GetEnumerator();
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}
}
public static class ObservableListExtensions
{
extension<T>(IObservableList<T> source) where T : notnull
{
public IObservableList<TResult> TransformVirtual<TResult>(Func<T, TResult> transformFactory) where TResult : notnull
{
ArgumentNullException.ThrowIfNull(source);
ArgumentNullException.ThrowIfNull(transformFactory);
return new ObservableListTransformVirtual<T, TResult>(source, transformFactory);
}
}
private sealed class ObservableListTransformVirtual<TSource, TResult> : IObservableList<TResult>
where TSource : notnull
where TResult : notnull
{
private readonly IObservableList<TSource> _source;
private readonly Func<TSource, TResult> _transformFactory;
public ObservableListTransformVirtual(IObservableList<TSource> source, Func<TSource, TResult> transformFactory)
{
_source = source;
_transformFactory = transformFactory;
}
public int Count => _source.Count;
public IObservable<int> CountChanged => _source.CountChanged;
public IReadOnlyList<TResult> Items => _source.Items.TransformVirtual(_transformFactory);
public void Dispose()
{
}
public IObservable<IChangeSet<TResult>> Connect(Func<TResult, bool>? predicate = null)
{
var ret = _source.Connect().Transform(_transformFactory);
if (predicate is not null)
{
ret = ret.Filter(predicate);
}
return ret;
}
public IObservable<IChangeSet<TResult>> Preview(Func<TResult, bool>? predicate = null)
{
var ret = _source.Preview().Transform(_transformFactory);
if (predicate is not null)
{
ret = ret.Filter(predicate);
}
return ret;
}
}
}
Sincerely thank all of you for creating DynamicData!
The steps the functionality will provide
From the end-user perspective:
- Call the new extension method
TransformVirtualon anyIObservableList/IObservableCacheto create another statelessIObservableList/IObservableCacheas a projected view without intermediate storage collection in a fluent way. - Transformation execution is on-demand and should be pure (no side effects). The
transformFactorywill run if items are accessed via indexer or enumeration. There is no precomputation or materialization, unless a subscription of a downstream observer viaConnectorPreviewoccurs. - Disposal of the returned
IObservableList/IObservableCacheis not required and does nothing because it's just a stateless wrapper. - Fully compatible with consumer scenarios that require direct index access, count property and enumeration support.
Considerations
Currently, in order to transform the elements of an IObservableList/IObservableCache, the Connect method needs to be called first and then use the Transform operator of observable change set. After that, the type of the current operating object becomes observable change set and the direct accessors of collection count and items are lost. In some cases, SourceList/SourceCaches are internally used and some transformed IObservableList/IObservableCaches should be exposed as public API. To revert to IObservableList/IObservableCache type, the method AsObservableList/AsObservableCache can be used, which creates intermediate storage collection (e.g. SourceList is created for IObservableList). If we just want to do a simple transformation, such as a type cast (even the implicit cast because covariance is not supported by DynamicData), this method is inefficient and unnecessary. To do this in a better way, we can just create a stateless wrapper of IObservableList/IObservableCache without inherent subscription and collection allocation.
- 主要言語
- C#
- スター
- 1.9k
- フォーク
- 194
- 平均マージ
- 12分
- マージ済み PR(30日)
- 1
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
reactivemarbles/DynamicData のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
reactivemarbles/DynamicData#1229 ·
メンテナーはふだん 1 日以内に返信
-
infrastructure
難易度 2/5 1〜3時間 初心者へのやさしさ 64/100
reactivemarbles/DynamicData#1089 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
[Bug]: ChangeAwareList merges an insert one slot before a pending AddRange, corrupting list order downstream対応中かも @dwcullop が 9 日前に担当しました。 オープンbug
難易度 3/5 半日 初心者へのやさしさ 63/100
reactivemarbles/DynamicData#1225 ·
メンテナーはふだん 1 日以内に返信
-
[Feature]: Make Avg, StdDev, Maximum and Minimum refresh-aware, consistent with Sum対応中かも @dwcullop が 14 日前に担当しました。 オープンbreaking change enhancement
難易度 5/5 1週間以上 初心者へのやさしさ 20/100
reactivemarbles/DynamicData#1214 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
reactivemarbles/DynamicData#1196 ·
メンテナーはふだん 1 日以内に返信
reactivemarbles/DynamicData の issue をすべて見る
似ている issue
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
immichFrame/ImmichFrame#735 ·
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
dimitar-radenkov/Pointframe#318 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
DotHarness/dotcraft#546 ·
メンテナーはふだん 1 日以内に返信
-
a-corriger bug
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
christian-raj/S-Aloha#303 · コメント 1 件 ·
-
Input editor says "Apply Changes" even when no changes have been made.対応中かも @hcooper が今日担当しました。 オープン
難易度 1/5 1時間未満 初心者へのやさしさ 72/100
MobiFlight/MobiFlight-Connector#3526 ·
メンテナーはふだん 1 日以内に返信