using System; using System.Collections.Immutable; public sealed class ImmutableListLens : ILens, Whole> { public readonly Func, Whole> wrap; private readonly ImmutableList oldHole; public ImmutableList value { get => oldHole; } public ImmutableListLens(Func, Whole> wrap, ImmutableList oldHole) { this.wrap = wrap; this.oldHole = oldHole; } // Put methods with the following signature here to focus on sub-parts of the list as needed. // public ILens,Whole> sub-part // => oldHole.sub-part.ChainLens(value => oldHole.with-sub-part(value)); public Whole Update(Func, ImmutableList> update) => wrap(update(oldHole)); } public static class ImmutableListLensExtensionMethods { public static ImmutableListLens ChainLens( this ImmutableList hole, System.Func, Whole> wrap) => new ImmutableListLens(wrap: wrap, oldHole: hole); public static ImmutableListLens> lens( this ImmutableList d) => d.ChainLens(x => x); }