Core/ChildrenExtensions.cs
using System;
using System.Collections.Generic;
namespace Goo;
// Auto-keying loop helper: AddRange runs the builder once per item and keys by index when the builder leaves Key == null. User-supplied keys win.
public static class ChildrenExtensions
{
public static void AddRange<T>(
this Children children,
IReadOnlyList<T> items,
Func<int, T, Container> builder )
{
for ( int i = 0; i < items.Count; i++ )
{
var child = builder( i, items[i] );
if ( child.Key is null )
child = child with { Key = $"_idx:{i}" };
children.Add( child );
}
}
}