Skip to content

Instantly share code, notes, and snippets.

View RolandPheasant's full-sized avatar
💭
In the mountains for a week,

Roland Pheasant RolandPheasant

💭
In the mountains for a week,
View GitHub Profile
@RolandPheasant
RolandPheasant / MergeManyFix.txt
Last active April 14, 2019 15:02
StackOverflow: MergeManyFix
using System;
using System.Collections.ObjectModel;
using System.Linq;
using System.Reactive;
using System.Reactive.Linq;
using DynamicData.Binding;
using FluentAssertions;
using ReactiveUI;
using Xunit;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Reactive.Linq;
using System.Text;
using System.Threading;
using DynamicData.Binding;
using Xunit;
using System.Threading;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Engines;
using DynamicData.Kernel;
namespace DynamicData.Benchmarks.List
{
[CoreJob]
[MarkdownExporterAttribute.GitHub]
public class LockingBenchmarks
@RolandPheasant
RolandPheasant / TransformInline
Last active June 20, 2022 15:29
Extension for a transform with an inline update
public static class DynamicDataEx
{
/// <summary>
/// Transforms the items, and when an update is received, allows the preservation of the previous view model
/// </summary>
/// <typeparam name="TObject">The type of the object.</typeparam>
/// <typeparam name="TKey">The type of the key.</typeparam>
/// <typeparam name="TDestination">The type of the destination.</typeparam>
/// <param name="source">The source.</param>
/// <param name="transformFactory">The transform factory.</param>
public class MyCalendarEntry
{
public int Id { get; }
public DateTime DateTime { get; }
public string Entry { get; }
public MyCalendarEntry(int id, DateTime dateTime, string entry)
{
Id = id;
DateTime = dateTime;
public static class ObservableEx
{
public static IObservable<IChangeSet<T>> BufferInitial<T>(this IObservable<IChangeSet<T>> source, TimeSpan initalBuffer, IScheduler scheduler = null)
{
return source.DeferUntilLoaded().Publish(shared =>
{
var initial = shared.Buffer(initalBuffer, scheduler ?? Scheduler.Default)
.FlattenBufferResult()
.Take(1);
public class ListFilterPerf
{
private static readonly ICollection<int> Items = Enumerable.Range(1, 1_000_000).ToList();
[Fact]
public void ListOnly_Range()
{
using System;
using System.Reactive.Disposables;
using System.Reactive.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace DynamicData.Tests.List
{
public static class ObservableChangeSet
{
@RolandPheasant
RolandPheasant / TransformMany.txt
Last active March 20, 2017 21:44
Transform many example (using observable collection)
/*
* This example works with observable collection. When using reactive list add package DynamicData.ReactiveUI (Use dynamic data v4x - later version are based off rx3x with rxui does not support)
* Normally with dd you would manage a collection independent of binding i.e. use SourceCache<T,K> or SourceList<T>, shape the collection and uae the Bind() operator to maintain an observable collection. See github homepage for links and examples
*/
ObservableCollection<A> listOfA = new ObservableCollection<A>();
//create a collection to bind to
ReadOnlyObservableCollection<B> binding;
//expand out the locations and create an ExpandableGroup which contains an inner cache of locations
IObservableCache<ExpandableGroup<Location>, GroupType> grouped = _internalLocations.Connect()
.TransformMany(CreateGroups, lwg => lwg.Key) //select one or more locations with a grouing
.Group(lwg => lwg.Type) //Create a nested cache
.Transform(grouping =>
{
//get original location back out of the grouping
var innerCache = grouping.Cache
.Connect()
.Transform(lwg => lwg.Location)