Skip to content

Instantly share code, notes, and snippets.

View Szer's full-sized avatar

Ayrat Hudaygulov Szer

View GitHub Profile
type IBuilderResult = interface end
type ICombinable = inherit IBuilderResult
type INonCombinable = inherit IBuilderResult
type First =
| Payload of int
| Nested of ICombinable
interface ICombinable
type Second =
| Payload of string
type IBuilderResult = interface end
type ICombinable = inherit IBuilderResult
type INonCombinable = inherit IBuilderResult
type First =
| Payload of int
| Nested of ICombinable
interface ICombinable
type Second =
| Payload of string
@Szer
Szer / seq_benches.fs
Created January 6, 2020 13:29
Seq performance
module Program
open System.Linq
open BenchmarkDotNet.Attributes
open BenchmarkDotNet.Running
[<SimpleJob(launchCount = 3, warmupCount = 3, targetCount = 5)>]
[<GcServer(true)>]
[<MemoryDiagnoser>]
[<MarkdownExporterAttribute.GitHub>]
@Szer
Szer / seq_benches_2.fs
Created January 6, 2020 14:13
seq benches 2
module Program
open System.Linq
open BenchmarkDotNet.Attributes
open BenchmarkDotNet.Running
[<SimpleJob(launchCount = 3, warmupCount = 3, targetCount = 5)>]
[<GcServer(true)>]
[<MemoryDiagnoser>]
[<MarkdownExporterAttribute.GitHub>]
@Szer
Szer / lazy.fs
Last active February 4, 2020 14:53
Lazy Builder
[<AutoOpen>]
module LazyBuilder =
let inline force(x: Lazy<_>) = x.Force()
type LazyCont<'a> = LazyCont of (unit -> Lazy<'a>)
type LazyBuilder() =
member __.Return x = lazy x
member __.ReturnFrom (x: Lazy<_>) = x
member __.Bind(Lazy x, f) = f x
member __.Delay f = LazyCont f
member __.Run (LazyCont f) = Lazy.Create (f >> force)
@Szer
Szer / refactor_bets.fs
Created February 24, 2020 14:22
F# refactor
module BetManager =
module SQL =
type BetChoice = abstract member IsD: bool
type Outcome = class end
type Item = abstract member Outcomes: Outcome seq
type Foo = abstract member Items: Item seq
@Szer
Szer / ExceptionHandling.fs
Created February 25, 2020 10:52
ExceptionHandling
open System
let (|Is|_|) (x: 'b) : 'a option =
match box x with
| :? 'a as a -> Some a
| _ -> None
let (|Inner|_|) (b: exn): 'a option when 'a :> Exception =
match box b.InnerException with
@Szer
Szer / combine-strings.fs
Created March 6, 2020 16:20
Combine Strings using ArrayPool
open System
open System.Buffers
open System.Text
let toOneArrayToRuleThemAll(strs: string[]) =
let ascii = System.Text.Encoding.ASCII
let totalBytes = Seq.sumBy String.length strs
let result = Array.zeroCreate totalBytes
@Szer
Szer / SeqPatterns.fs
Last active June 17, 2020 23:16
Pattern matching for all sequences
open System
[<RequireQualifiedAccess>]
module Seq =
let inline (|Nil|Cons|) (someSeq: seq<_>) =
let mutable enum = Unchecked.defaultof<IEnumerator<_>>
let mutable shouldDispose = true
try
@Szer
Szer / results.md
Last active April 7, 2020 18:22
tryPick benches

Summary

BenchmarkDotNet=v0.12.0, OS=macOS 10.15.3 (19D76) [Darwin 19.3.0]
Intel Core i9-9880H CPU 2.30GHz, 1 CPU, 16 logical and 8 physical cores
.NET Core SDK=3.1.100
  [Host]     : .NET Core 3.1.0 (CoreCLR 4.700.19.56402, CoreFX 4.700.19.56404), X64 RyuJIT DEBUG
  Job-FLMOIG : .NET Core 3.1.0 (CoreCLR 4.700.19.56402, CoreFX 4.700.19.56404), X64 RyuJIT

Server=True  IterationCount=5  LaunchCount=3  
WarmupCount=3