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 "System.Management" | |
open System.Management | |
do | |
use ma = new ManagementObjectSearcher("Select * from Win32_Processor") | |
for item in ma.Get() do | |
try | |
printfn "%A" item.["NumberOfCores"] | |
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 cell init = | |
MailboxProcessor.Start(fun inbox -> | |
let rec loop n = | |
async { | |
let! result = inbox.Receive() | |
printfn "Received %d" result | |
return! loop result | |
} | |
loop init |
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 parse str = (^a: (static member Parse: string -> ^a) (str)) | |
let inline tryParse str = | |
let mutable value = Unchecked.defaultof<_> | |
let result = (^a: (static member TryParse: string * byref< ^a > -> bool) (str, &value)) | |
result, value | |
(tryParse "3": bool * int) | |
(tryParse "2.3": bool * float) | |
(tryParse "2.3": bool * decimal) |
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:\Projects\Lib\System.Reactive.Interfaces.dll" | |
#r @"C:\Projects\Lib\System.Reactive.Core.dll" | |
#r @"C:\Projects\Lib\System.Reactive.Linq.dll" | |
open System | |
open System.Linq | |
open System.Reactive.Subjects | |
open System.Reactive.Linq | |
let run n m = |
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
//Hi Julie, I liked your article and couldn't resist offering some possible improvements. I don't know | |
//what all the formulae mean but F#'s pattern matching is pretty powerful but also extensible and can | |
//be used to greatly improve readability and your chances of getting the code right in the first go. | |
// | |
//Below you can see the definition of two Active Pattern to extend F#'s pattern matching with a way | |
//to extract information from simple values, in this case floats. | |
let (|GreaterThan|_|) num = function | |
| value when value > num -> Some () | |
| _ -> None |
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
query { | |
for order in db.Orders do | |
let status = | |
match order.Status with | |
| 0 | 1 -> "Cancelled/Returned" | |
| _ -> "Valid" | |
where (status = "Valid") | |
select order | |
} |
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 Order = | |
type T = Order of int | |
let get (db: DataContext) id = | |
query { | |
for order in db.Orders do | |
where (order.Id = id) | |
select (Order id) | |
exactlyOne | |
} |
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 FileChange = | |
| Changed of string | |
| Deleted of string | |
| Created of string | |
| Renamed of string * string | |
let watch folder = | |
async { | |
use fsw = new System.IO.FileSystemWatcher(folder, "*.fsx", EnableRaisingEvents = true) | |
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 (|Empty|_|) = function | |
| xs when Set.isEmpty xs -> Some () | |
| _ -> None | |
[ | |
"rule1", ["192"; "193"] | |
"rule2", ["193"; "194"] | |
"rule3", ["194"; "195"] | |
] | |
|> Seq.fold (fun data (rule, dst) -> |
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 data = | |
query { | |
for packet in communicator.ReceivePackets() do | |
// where (not packet.IsValid) | |
select packet | |
} |