This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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<_> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// No early return | |
// Prints "gotcha" | |
async { | |
return () | |
printfn "gotcha" | |
} | |
|> Async.RunSynchronously | |
// Early return | |
// Does not print anything |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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() | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Equatable operators - avoid boxing operands when comparing structs. | |
/// Source: https://github.com/dotnet/fsharp/issues/526#issuecomment-119755563 | |
module EquatableOperators = | |
let inline eq<'a when 'a :> System.IEquatable<'a>> (x:'a) (y:'a) = x.Equals y | |
let inline (==) x y = eq x y | |
let inline (!=) x y = not (eq x y) | |
/// We get a fair warning that it's odd that we impl. custom equality | |
/// when we deny the equality operator. | |
[<Struct; NoEquality; NoComparison>] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Compile-time error on contradictive conditional compilation symbols. | |
// Make conditional compilation symbols form a discriminated union. | |
#if (SITE_DEV && SITE_TEST) | |
§"Contradictive conditional compilation symbols" | |
#endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Query Kind="Statements"> | |
<Namespace>System.Net.Http</Namespace> | |
<Namespace>System.Threading.Tasks</Namespace> | |
<Namespace>System.Dynamic</Namespace> | |
</Query> | |
await TestAsync("Foo", http => http.GetStringAsync("http://www.google.com/"), HttpFormatOptions.Verbose); | |
static object Title(string message, bool isError = false) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Query Kind="Program"> | |
<NuGetReference>Observito.Trace.EventSourceFormatter</NuGetReference> | |
<Namespace>Observito.Trace.EventSourceFormatter</Namespace> | |
<Namespace>System.Collections.Immutable</Namespace> | |
<Namespace>System.Diagnostics.Tracing</Namespace> | |
</Query> | |
#nullable enable | |
void Main() |
NewerOlder