Skip to content

Instantly share code, notes, and snippets.

View bent-rasmussen's full-sized avatar

Bent Rasmussen bent-rasmussen

View GitHub Profile
@bent-rasmussen
bent-rasmussen / NoBoxStruct.fs
Last active February 21, 2022 17:16
How I learned to love the struct and stop worrying (part II)...
// Use the Test solution configuration and now test cases will fail if they are using '=' on structs.
#if STRUCT_EQ_CHECK
[<AutoOpen>]
#endif
module StructEqCheck =
type StructEqualityException() =
inherit exn()
@bent-rasmussen
bent-rasmussen / EarlyReturn.fs
Created April 26, 2022 09:01
F# async workflow early return
// No early return
// Prints "gotcha"
async {
return ()
printfn "gotcha"
}
|> Async.RunSynchronously
// Early return
// Does not print anything
@bent-rasmussen
bent-rasmussen / OrdinalIgnoreCaseString.fs
Last active June 8, 2023 08:40
OrdinalIgnoreCaseString - an F# string type that is case-insensitive
// Experiment
open System
open System.Collections.Generic
open System.Runtime.CompilerServices
// Case-insensitive strings for ValueTuple embedding.
[<IsReadOnly; Struct; CustomEquality; CustomComparison>]
type OrdinalIgnoreCaseString =
{ Value: string }
@bent-rasmussen
bent-rasmussen / vide-todo-list.linq
Created November 25, 2023 09:57
Vide todo-list sample in a LINQPad script (F#, Avalonia)
<Query Kind="FSharpProgram">
<NuGetReference>Avalonia</NuGetReference>
<NuGetReference>Avalonia.Desktop</NuGetReference>
<NuGetReference>Avalonia.Themes.Fluent</NuGetReference>
<NuGetReference>Vide.UI.Avalonia</NuGetReference>
<Namespace>Avalonia</Namespace>
<Namespace>Vide</Namespace>
<Namespace>Vide.UI.Avalonia</Namespace>
</Query>
@bent-rasmussen
bent-rasmussen / Trace.fs
Last active July 30, 2025 21:58
F# Trace
open System
open System.Diagnostics
open System.Runtime.CompilerServices
open System.Runtime.InteropServices
let activitySource = new ActivitySource("Test")
[<IsReadOnly; Struct>]
type Trace<'T>(activitySource: ActivitySource) =
static let typeName = typeof<'T>.Name
@bent-rasmussen
bent-rasmussen / Option2-double-trouble.fs
Last active September 3, 2025 22:19
No total triple trouble; only double trouble
// Experiment.
//
// If I have a combination of optional types, and want to operate on them
// it is tedious to have to pick the right functions based on precise
// option type, rather than just do a "flatten this value, I don't care
// which combination of Option<_> or ValueOption<_> it is - just make it happen!"
//
// So:
// Mix and match Option<_> and ValueOption<_>
// Results are Option<_>