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
(* | |
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`: |
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
// In *.fsproj add: | |
// <PropertyGroup > | |
// <WarningsAsErrors>FS0025</WarningsAsErrors> | |
// </PropertyGroup> | |
module Tests | |
open System | |
open Xunit |
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
module Tests | |
open System | |
open Xunit | |
type IFoo = | |
abstract Foo1 : string | |
abstract Foo2 : unit -> string | |
abstract Foo3 : string -> 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 @"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 = |
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
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 '(' |
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 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 = |
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
let inline (^) f x = f x | |
[||] | |
|> Array.map ^ fun x -> x + 1 | |
|> Array.iter ^ fun x -> printfn "%i" 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
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' |
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
module Tests | |
open System | |
open System.Text | |
open System.Threading.Tasks | |
open System.Diagnostics | |
open Xunit | |
open RabbitMQ.Client | |
open RabbitMQ.Client.Events |
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
module Parser | |
open System | |
open System.IO | |
open System.Text | |
open System.Text.RegularExpressions | |
open FSharp.Control.AsyncSeqExtensions | |
open FSharp.Control | |
type Event = { |
OlderNewer