This file contains 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.Runtime.CompilerServices | |
type Log() = | |
static member inline GatherLogMeta | |
( | |
?name_space: string, | |
[<CallerMemberName>] ?cmb: string, | |
[<CallerLineNumber>] ?cln: int, | |
[<CallerFilePath>] ?cfp: string | |
) = |
This file contains 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
#r "nuget: FSharp.Compiler.Service, 43.8.300" | |
open FSharp.Compiler.Syntax | |
open FSharp.Compiler.SyntaxTrivia | |
open FSharp.Compiler.Xml | |
open FSharp.Compiler.CodeAnalysis | |
open System.IO | |
type Node = | |
{ Data : Data |
This file contains 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
type ResultBuilder () = | |
member inline _.Return (x) = Ok x | |
member inline _.Bind(x,f) = | |
match x with | |
| Ok x -> f x | |
| Error e -> Error <| e |
This file contains 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.IO | |
open System.Collections.Generic | |
let root = __SOURCE_DIRECTORY__ | |
let srcDir = Path.Combine(root, "src") | |
// Add <OtherFlags>$(OtherFlags) --test:GraphBasedChecking --test:DumpCheckingGraph --times:timings.csv</OtherFlags> to the .fsproj or Directory.Build.props |
This file contains 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.Threading.Tasks | |
type FooBuilder() = | |
member _.Return(x) = Task.FromResult(Ok x) | |
member _.Bind(x, f) : Task<Result<'TResult, 'Error list>> = | |
task { | |
let! x = x |
This file contains 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
namespace FsToolkit.ErrorHandling.Ducks | |
open System | |
open System.Collections.Generic | |
open System.Threading.Tasks | |
open System.Runtime.CompilerServices | |
open Microsoft.FSharp.Core.CompilerServices | |
type Disposable<'Disposable when 'Disposable: (member Dispose: unit -> unit)> = 'Disposable |
This file contains 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.Threading | |
open System.Threading.Tasks | |
// Based on https://gist.github.com/StephenCleary/7dd1c0fc2a6594ba0ed7fb7ad6b590d6 | |
// and https://gist.github.com/brendankowitz/5949970076952746a083054559377e56 | |
/// <summary> | |
/// An awaitable wrapper around a task whose result is disposable. The wrapper is not disposable, so this prevents usage errors like "use _lock = myAsync()" when the appropriate usage should be "use! _lock = myAsync())". |
This file contains 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
#r "nuget: Serilog, 2.9.0" | |
open System.Threading.Tasks | |
[<Interface>] | |
type ILogger = | |
abstract Debug: string -> unit | |
abstract Error: string -> unit | |
[<Interface>] |
This file contains 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
type BlockingObjectPool<'T when 'T : (new : unit -> 'T)>(maxCount : int) = | |
let pool = Stack<'T>(maxCount) | |
let semaphoreSlim = new SemaphoreSlim(maxCount, maxCount) | |
do for i=0 to maxCount do | |
let foo = new 'T() | |
pool.Push(foo) | |
member _.Get() = | |
printf $"Getting from pool : {semaphoreSlim.CurrentCount}" | |
semaphoreSlim.Wait() |
This file contains 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 | |
// Replace with your type | |
type MyType<'a> = Async<'a> | |
type Internal<'a> = MyType<'a> | |
// Replace with types that feel similar and can be converted to `MyType` | |
type External1<'a> = System.Threading.Tasks.Task<'a> | |
type External2<'a> = System.Threading.Tasks.ValueTask<'a> |
NewerOlder