This file contains hidden or 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 StrRef = | |
| { str: string | |
| start: int | |
| length: int } | |
| [<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>] | |
| module StrRef = | |
| let substring n s = { s with length=(min s.length n) } | |
| let lastPos sr = sr.start + sr.length - 1 | |
| let iterate sr = |
This file contains hidden or 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
| // v9 | |
| module TiraxTech.Foundation | |
| let inline sideEffect ([<InlineIfLambda>] f) x = (f x); x | |
| let inline flip f a b = f b a | |
| let inline constant x = fun _ -> x | |
| let inline cast<'t> (x :obj) = x :?> 't | |
| let inline tryCast<'a> (x:obj) = |
This file contains hidden or 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 Microsoft.Win32 | |
| let inline constant x = fun _ -> x | |
| type RegistryEntry = | |
| | Key of RegistryKey * string list | |
| | Value of RegistryKey * string list * obj | |
| let inline tryCast<'a> (x:obj) = |
This file contains hidden or 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 "System.Net.Http.dll" | |
| #r "packages/Newtonsoft.Json/lib/net45/Newtonsoft.Json.dll" | |
| #load "paket-files/ruxo/a9244a6dfe5e73337261/common.fs" | |
| #load "paket-files/ruxo/5e1e84865bafd17e3a34/pair.fs" | |
| open System | |
| open System.Net | |
| open RZ | |
| open RZ.Foundation |
This file contains hidden or 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 CategoryFunc = float -> float | |
| type Category = string * CategoryFunc | |
| module private CategoryRandom = | |
| let r = System.Random() | |
| let from n = r.Next n | |
| [<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>] | |
| module Category = |
This file contains hidden or 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 TreeNode<'a> = 'a * 'a seq | |
| let rec traverse (prefix: 'a list) (lookup: 'a -> TreeNode option) (x:'a, subnodes: 'a seq) :'a list seq = | |
| seq { | |
| let routes = x::prefix | |
| yield routes | |
| let nextScan = subnodes |> Seq.filter (fun x' -> not (routes |> List.contains x')) | |
| for n in nextScan do | |
| match lookup n with |
This file contains hidden or 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 combinationPair array = | |
| seq { | |
| let L = Array.length array | |
| for i = 0 to L-2 do | |
| let first = array.[i] | |
| for j = i+1 to L-1 do | |
| yield first, array.[j] | |
| } | |
| let combinationDoubleSeq a1 a2 = a1 |> Seq.collect (fun x -> a2 |> Seq.map (fun y -> x,y)) |
This file contains hidden or 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 Rect = | |
| { Left:int; Top:int; Width:int; Height:int } | |
| with | |
| static member create(w, h) = { Left=0; Top=0; Width=w; Height=h } | |
| static member create(l,t,r,b) = { Left=l; Top=t; Width=(r-l)+1; Height=(b-t)+1 } | |
| static member shrink n r = { Left=r.Left+n; Top=r.Top+n; Width=r.Width-2*n; Height=r.Height-2*n } | |
| static member scan r = | |
| seq { | |
| for y = r.Top to r.Top+r.Height-1 do | |
| for x = r.Left to r.Left+r.Width-1 do |
This file contains hidden or 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
| def memoize(method_name) | |
| cache = {} | |
| define_method(method_name) do |*args| | |
| cache[args] ||= yield(*args) | |
| end | |
| end | |
| memoize(:add) {|a,b| | |
| p "calc #{a} and #{b}" | |
| a+b |
This file contains hidden or 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 FP | |
| class Either | |
| def initialize(data) | |
| @data = data | |
| end | |
| def get | |
| @data | |
| end | |
| end | |
| class Right < Either |