Skip to content

Instantly share code, notes, and snippets.

View davidgrenier's full-sized avatar

David Grenier davidgrenier

View GitHub Profile
#I "../hopac/Libs/Hopac/bin/Release/net7.0/"
#r "Hopac.Core"
#r "Hopac.Platform"
#r "Hopac"
#load "./Bench.fs"
open System
open System.Threading
open Hopac.Extensions
open Hopac.Infixes
@davidgrenier
davidgrenier / PatternMatchingQuery.fsx
Created January 2, 2014 14:44
Pattern matching query
query {
for order in db.Orders do
let status =
match order.Status with
| 0 | 1 -> "Cancelled/Returned"
| _ -> "Valid"
where (status = "Valid")
select order
}
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
}
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)
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) ->
let data =
query {
for packet in communicator.ReceivePackets() do
// where (not packet.IsValid)
select packet
}
let numBuffers = 50
[1; 2; 3; 4; 5]
|> Seq.mapi (fun i x -> i, x)
|> Seq.groupBy (fun (i, _) -> i % numBuffers)
|> Seq.map (fun (_, group) -> group |> Seq.map snd |> Seq.toArray)
|> Seq.toArray
let bufferSize = 500
[1; 2; 3; 4; 5]
|> Seq.mapi (fun i x -> i, x)
type PagePath =
| [<Require(typeof<kendo.Resources.Culture.French>)>] FR
| [<Require(typeof<kendo.Resources.Culture.English>)>] EN
open System;
open System.Diagnostics;
[<EntryPoint>]
let main argv =
let rec cc amount coins =
match (amount, coins) with
| (0,_) -> 1
| (_,[]) -> 0
| (amount,_) when amount < 0 -> 0
open System;
open System.Diagnostics;
[<EntryPoint>]
let main argv =
let rec cc amount coins =
match (amount, coins) with
| (0,_) -> 1
| (_,[]) -> 0
| (amount,_) when amount < 0 -> 0