DotNext by .NET Foundation and Contributors

<PackageReference Include="DotNext" Version="4.6.0" />

.NET API 538,048 bytes

 SupplierClosure<TContext, T, TResult>

public struct SupplierClosure<TContext, T, TResult> : ISupplier<T, TResult>
Represents implementation of ISupplier<T, U> interface with the support of closure that is not allocated on the heap.
using System; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace DotNext { [StructLayout(LayoutKind.Auto)] [System.Runtime.CompilerServices.NullableContext(2)] [System.Runtime.CompilerServices.Nullable(0)] [CLSCompliant(false)] public readonly struct SupplierClosure<TContext, T, TResult> : ISupplier<T, TResult> { private readonly IntPtr ptr; private readonly TContext context; public unsafe bool IsEmpty => ptr == (IntPtr)(void*)null; [System.Runtime.CompilerServices.NullableContext(1)] public unsafe SupplierClosure([System.Runtime.CompilerServices.Nullable(new byte[] { 0, 1, 1, 1 })] IntPtr ptr, TContext context) { if (ptr == (IntPtr)(void*)null) throw new ArgumentNullException("ptr"); this.ptr = ptr; this.context = context; } TResult ISupplier<T, TResult>.Invoke(T arg) { IntPtr intPtr = ptr; return (TResult); } } }