Skip to content

Instantly share code, notes, and snippets.

View GeneratedDI.cs
namespace CsDI
{
partial record DI
{
IY? _singletonOf_IY;
IZ? _singletonOf_IZ;
public void Get(out IX v)
{
@mrange
mrange / GenAll.cs
Last active Jun 12, 2022
T4 template to generate all version of a model
View GenAll.cs
namespace CsGenAll
{
using System.Diagnostics;
// BooleanValue - BEGIN
// Kind: IsEnum
public enum BooleanValue
{
@mrange
mrange / GenAll.tt
Last active Jun 11, 2022
GenAll T4
View GenAll.tt
<#@ assembly name ="System.Core" #>
<#@ import namespace ="System.Linq" #>
<#
var model = new []
{
Union(
"BooleanValue"
, Case("False")
@mrange
mrange / Benchmark.fsproj
Last active Jun 9, 2022
Testing Fusion vs Fission in F#
View Benchmark.fsproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Compile Include="Program.fs" />
</ItemGroup>
@mrange
mrange / 0_README.md
Last active Jun 12, 2022
FsGenAll - Generate all possible values for an F# type
View 0_README.md

FsGenAll - Generate all possible values for an F# type

writing test code I often use FsCheck. However, sometimes I want to generate each possible value for a test model and check the properties for that.

My typical use case is something like this:

  1. Create an ADT that models what I want to test
  2. Generate all possible values of this test model
  3. Generate test data from the test model
  4. Run the function under test that produces a result
@mrange
mrange / genall.fs
Last active Jun 6, 2022
F# Gen All
View genall.fs
type 'T PushStream = ('T -> bool) -> bool
// I wrote a blog about PushStream for F# advent 2022
// https://github.com/mrange/PushStream6
// I am appealed to them both because of their simplicity and performance
// When generating values I need a place to my values after creation
// PushStreams turn out to be very convenient
module PushStream =
[<GeneralizableValue>]
let empty<'T> : 'T PushStream = fun r -> true
@mrange
mrange / RecordArray.cs
Last active May 31, 2022
RecordArray - Reasonable ToString and comparison for sequences in records.
View RecordArray.cs
using System.Collections;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace Shared
{
partial class RecordArrayConverter<T> : JsonConverter<RecordArray<T>>
{
public RecordArrayConverter() {}
View Mandelbrot.fsproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Compile Include="Program.fs" />
</ItemGroup>
@mrange
mrange / 0_README.md
Last active May 15, 2022
Dynamic JSON in C#
View 0_README.md

Dynamic JSON in C#

How to run

  1. Install dotnet: https://dotnet.microsoft.com/en-us/download
  2. Create a folder named for example: CsDymamic
  3. Create file in the folder named: CsDyamic.csproj and copy the content of 1_CsDyamic.csproj into that file
  4. Create file in the folder named: Program.cs and copy the content of 2_Program.cs below into that file
  5. Launch the application in Visual Studio or through the command line dotnet run from the folder CsDymamic
@mrange
mrange / 0_README.md
Last active Apr 24, 2022
Landing Ship in F#
View 0_README.md

Landing a rocket

How to run

  1. WPF requires a Windows box
  2. Install dotnet: https://dotnet.microsoft.com/en-us/download
  3. Create a folder named for example: FsLanding
  4. Create file in the folder named: FsLanding.fsproj and copy the content of 1_FsLanding.fsproj below into that file
  5. Create file in the folder named: Program.fs and copy the content of 2_Program.fs below into that file
  6. Launch the application in Visual Studio or through the command line dotnet run from the folder FsLanding