Skip to content

Instantly share code, notes, and snippets.

Avatar

Szer

  • Jet.com
  • Dublin, Ireland
View GitHub Profile
View AsyncResult.fs
module AsyncResultModule
type AsyncResult<'a> = Async<Result<'a, exn>>
[<RequireQualifiedAccess>]
module AsyncResult =
// Few basic functions
let bind (f: 'a -> AsyncResult<'b>) (a: AsyncResult<'a>): AsyncResult<'b> =
@Szer
Szer / actor_bench.fs
Created May 23, 2020
Benchmark of memory footproing on sending myriad of messages to myriad of actors
View actor_bench.fs
module Bench
open System
open BenchmarkDotNet.Attributes
open BenchmarkDotNet.Running
open Hopac
open Hopac.Infixes
open Akka.FSharp
[<SimpleJob(launchCount = 3, warmupCount = 3, targetCount = 5)>]
View exchange-rates.fs
open FSharp.Data
open XPlot.Plotly
let url = sprintf "https://bank.gov.ua/markets/exchangerates?date=%s&period=daily"
type Currency = HtmlProvider<"https://bank.gov.ua/markets/exchangerates?date=03.05.2020&period=daily", Culture = "ru-RU">
let dates =
[|1..30|]
|> Array.map (sprintf "%02d.04.2020")
@Szer
Szer / stepfulBuilder.fs
Last active Jul 27, 2020
Computational expression with state being passed through steps
View stepfulBuilder.fs
type StepfulBuilder() =
member _.Zero() = ()
member _.Yield x = x
[<CustomOperation("toInt")>]
member inline _.ToInt(_, value) =
int value
[<CustomOperation("transform")>]
member _.Transform(x, f) =
@Szer
Szer / sameCaseCheck.fs
Last active Apr 10, 2020
Concise check if cases of DU are the same
View sameCaseCheck.fs
open System
open System.Collections.Concurrent
open Microsoft.FSharp.Reflection
open Microsoft.FSharp.Quotations.Patterns
type UnionUtils =
static member private isTypeUnionCache = ConcurrentDictionary<Type, bool>()
static member private tagGetterCache = ConcurrentDictionary<Type, obj -> int>()
@Szer
Szer / effect.fs
Last active Apr 10, 2020
This is a joke
View effect.fs
type Effect<'env, 'out> = Effect of ('env -> 'out)
module Effect =
let value x = Effect (fun _ -> x)
let apply f = Effect f
let run env (Effect f) = f env
let run' (Effect f) env = f env
let map f (Effect g) = Effect(f << g)
let local f (Effect g) = Effect(f >> g)
let inline bind f effect =
Effect (fun env ->
@Szer
Szer / results.md
Last active Apr 7, 2020
tryPick benches
View results.md

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  
@Szer
Szer / SeqPatterns.fs
Last active Jun 17, 2020
Pattern matching for all sequences
View SeqPatterns.fs
open System
[<RequireQualifiedAccess>]
module Seq =
let inline (|Nil|Cons|) (someSeq: seq<_>) =
let mutable enum = Unchecked.defaultof<IEnumerator<_>>
let mutable shouldDispose = true
try
@Szer
Szer / combine-strings.fs
Created Mar 6, 2020
Combine Strings using ArrayPool
View combine-strings.fs
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
View ExceptionHandling.fs
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
You can’t perform that action at this time.