Skip to content

Instantly share code, notes, and snippets.

View Tarmil's full-sized avatar

Loïc Denuzière Tarmil

View GitHub Profile
open System.Text.Json
open System.Text.Json.Serialization
open BenchmarkDotNet.Attributes
open BenchmarkDotNet.Running
type MyUnion =
| Foo
| Bar of int * string
type Unions() =
open System.IO
open System.Threading.Tasks
open FSharp.Control.Tasks.TaskBuilder
open FSharp.Control.Tasks.V2
type UnitTaskBuilder() =
inherit TaskBuilderV2()
member _.Run(x) = base.Run(x) :> Task
let utask = UnitTaskBuilder()
// A reply to: https://twitter.com/davidfowl/status/1282445306261471232
// This implements a connection of some kind that can be started and stopped asynchronously.
// We must ensure that we don't try to start it while it is stopping or vice-versa.
// A few internal types first...
/// Contains whatever state needs to be held on to while connected.
type private ConnectedState = { Id: int }
/// The state of the internal agent. Describes the current status of the connection,
using System;
using System.Collections.Generic;
using System.Linq;
var coll = Enumerable.Range(1, 10);
// We need to repeat "int" here, it can't be implied by IntAdd or IntMul :(
Console.WriteLine($"The sum is {AppendMany<IntAdd, int>(coll)}");
Console.WriteLine($"The product is {AppendMany<IntMul, int>(coll)}");
type Attr = delegate of RenderTreeBuilder * int -> int
type Node = delegate of RenderTreeBuilder * int -> int
type NodeBuilder(name: string) =
static member Empty = Node(fun _sb x -> x)
member _.Name = name