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 itemsProp arg = (^a : (member Items : ItemCollection) arg) | |
let inline withBackground brush e = (^a : (member set_Background : Brush -> unit) (e, brush)) |
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 genString = | |
let rand = System.Random() | |
let chars = [|'A'..'Z'|] |> Array.append [|'a'..'z'|] | |
fun n -> System.String (Array.init n (fun _ -> chars.[rand.Next(0, chars.Length)])) | |
genString 10 |
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 transpose3 = function | |
| [||] -> [||] | |
| a -> | |
Array.maxBy Array.length a | |
|> Array.Parallel.mapi (fun i _ -> | |
Array.filter (fun js -> Array.length js > i) a | |
|> Array.map (fun sub -> sub.[i]) | |
) |
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
#load @"C:\Bib\Projects\FSharpChart\F#\scripts\FSharpChart.fsx" | |
#r @"C:\Bib\Projects\FSharp.Data\src\bin\Release\FSharp.Data.dll" | |
open FSharp.Data | |
open MSDN.FSharp.Charting | |
type Types = CsvProvider<"""C:\Users\dgrenier\Desktop\race_data.csv"""> | |
let data = Types.Load """C:\Users\dgrenier\Desktop\race_data.csv""" |
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:\Bib\Projects\FSharp.Data\src\bin\Release\FSharp.Data.dll" | |
open FSharp.Data | |
let data = WorldBankData.GetDataContext() | |
let ``Sergey's data`` = | |
[ | |
"United States", 11823 | |
"United Kingdom", 4256 |
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 rec (|Run|_|) n c = | |
let rec identicals n = function | |
| rest when n = 0 -> Some rest | |
| a :: rest when a = c && n > 0 -> identicals (n - 1) rest | |
| _ -> None | |
identicals n |
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 (|ModZero|_|) d v = | |
match v % d with | |
| 0 -> Some () | |
| _ -> None | |
let fizzBuzz = function | |
| ModZero 15 -> printfn "fizzbuzz" | |
| ModZero 3 -> printfn "fizz" | |
| ModZero 5 -> printfn "buzz" | |
| i -> printfn "%i" i |
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 add3times2minus4 = | |
let add3 x = x + 3 | |
let times2 x = x * 2 | |
let minus4 x = x - 4 | |
[ | |
add3 | |
times2 | |
minus4 | |
] |> Seq.reduce (>>) |
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
[<Measure>] | |
type m | |
[<Measure>] | |
type s | |
type Vector<[<Measure>] 't> = | |
{ X: float<'t>; Y: float<'t> } | |
with |
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 trySwap (source: obj ref) replacement = | |
let before = !source | |
let result = System.Threading.Interlocked.CompareExchange(source, replacement, before) | |
System.Object.ReferenceEquals(before, result) |