Skip to content

Instantly share code, notes, and snippets.

(*
WHAT'S GOING ON HERE?!
Sometimes you don't care about a particular type, you're interested in one field only, let's say `EntityId`.
Instead of using interface (which isn't even possible if don't own a type),
we can do structural typing in F# using SRTP and Active Patterns.
Active patterns are not required for this, but they do make code much easier to use.
*)
// So we have 2 types with field `EntityId: string`:
// In *.fsproj add:
// <PropertyGroup >
// <WarningsAsErrors>FS0025</WarningsAsErrors>
// </PropertyGroup>
module Tests
open System
open Xunit
module Tests
open System
open Xunit
type IFoo =
abstract Foo1 : string
abstract Foo2 : unit -> string
abstract Foo3 : string -> string
@medigor
medigor / code-gen2.fs
Created September 17, 2019 09:02 — forked from Szer/code-gen2.fs
Generate type serialization tests because I'm lazy
#r @"C:\Users\ayrat.hudaygulov\.nuget\packages\fsharp.compiler.service\26.0.1\lib\net45\FSharp.Compiler.Service.dll"
open System.IO
open Microsoft.FSharp.Compiler.Ast
open Microsoft.FSharp.Compiler.SourceCodeServices
let parse text =
let fileName = "whatever.fs"
let checker = FSharpChecker.Create()
let opts =
@medigor
medigor / Brackets.fs
Last active September 25, 2019 19:43
let validate (str: string) =
let rec loop (i: int) (acc: char list) =
if i >= str.Length then
acc.IsEmpty
else
let validateChar ch =
not acc.IsEmpty && acc.Head = ch && loop (i + 1) acc.Tail
match str.[i] with
| '(' | '[' | '{' -> loop (i + 1) (str.[i]::acc)
| ')' -> validateChar '('
type EventStream<'T> ()=
let evt=Channel.CreateUnbounded<'T>()
let writer = evt.Writer
let reader = evt.Reader
let mutable key = 0
let mutable subscriptions = Map.empty : Map<int, IObserver<'T>>
let thisLock = new obj()
let obs =
let inline (^) f x = f x
[||]
|> Array.map ^ fun x -> x + 1
|> Array.iter ^ fun x -> printfn "%i" x
type WriteAny = WriteAny with
static member inline ($) (x: char, _) = Console.Write x
static member inline ($) (x: string, _) = Console.Write x
let inline write any = any $ WriteAny
write "1"
write '1'
module Tests
open System
open System.Text
open System.Threading.Tasks
open System.Diagnostics
open Xunit
open RabbitMQ.Client
open RabbitMQ.Client.Events
module Parser
open System
open System.IO
open System.Text
open System.Text.RegularExpressions
open FSharp.Control.AsyncSeqExtensions
open FSharp.Control
type Event = {