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 TypeUtility | |
[<CompiledName("SafeGetType")>] | |
let safeGetType<'a> (value : 'a) = typeof<'a> |
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
// Usage: | |
// 1. Fsi.exe NUnitAssemblyPathConvertor.fsx BarTest.nunit | |
// 2. Get-Content FooTest.nunit | Fsi.exe NUnitAssemblyPathConvertor.fsx | |
#r "System.Xml.Linq.dll" | |
open System | |
open System.IO | |
open System.Xml.Linq | |
open Microsoft.FSharp.Core.LanguagePrimitives |
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
<?xml version="1.0" encoding="utf-8" ?> | |
<!-- | |
To run: MSBuild /nologo /verbosity:minimal fizzbuzz.proj | |
--> | |
<Project DefaultTargets="FizzBuzz" | |
xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | |
<PropertyGroup Condition=" '$(Current)' == '' "> | |
<Current>1</Current> |
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 invoke action = action () | |
let repeat n action = Seq.initInfinite (fun _ -> action) |> Seq.take n |> Seq.iter invoke | |
let slowPrint (delay : int) = | |
fun () -> | |
System.Threading.Thread.Sleep (delay) | |
System.Console.WriteLine (System.DateTime.Now) | |
slowPrint 500 |> repeat 120 |
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 RandomAccessList | |
open System | |
let indexOutOfBounds = ArgumentOutOfRangeException ("index") | |
let emptyList = ArgumentException ("Empty list") | |
type Tree<'a> = | |
| Leaf of 'a | |
| Node of 'a * 'a Tree * 'a Tree |
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 transform (xslt : string) (document : XDocument) = | |
let transformer = XslCompiledTransform () | |
transformer.Load (xslt) | |
let builder = StringBuilder () | |
use writer = XmlWriter.Create (builder, transformer.OutputSettings) | |
use reader = document.CreateReader () | |
transformer.Transform (reader, writer) | |
builder.ToString () |> XDocument.Parse |
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 ofType<'a> (source : System.Collections.IEnumerable) : seq<'a> = | |
let resultType = typeof<'a> | |
seq { | |
for item in source do | |
match item with | |
| null -> () | |
| _ -> | |
if resultType.IsAssignableFrom (item.GetType ()) | |
then | |
yield (downcast item) |
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 buffered<'a> bufferSize (source : seq<'a>) = | |
seq { | |
use enumerator = source.GetEnumerator () | |
let incomplete = ref true | |
while !incomplete do | |
let buffer = | |
seq { | |
let request = ref bufferSize | |
while !request > 0 && enumerator.MoveNext () do | |
yield enumerator.Current |
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 FizzBuzz | |
{ | |
var convert = function (fb : FizzBuzz, n : number) : string | |
{ | |
var buffer = "" | |
for (var current = fb; current != null; current = current.next) | |
{ | |
buffer = current.consume (n, buffer) | |
} | |
if (buffer.length == 0) |
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 whileLoop condition f seed = | |
seq { | |
yield seed | |
yield! Seq.unfold (fun s -> if condition s then let next = f s in Some (next, next) else None) seed | |
} | |
|> Seq.last | |
let doWhileLoop condition f seed = whileLoop condition f (f seed) |
OlderNewer