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
| [<Struct>] | |
| type Foo = | |
| val mutable bar: string | |
| member self.ChangeBar bar = self.bar <- bar | |
| new (bar) = {bar = bar} |
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 System.String with | |
| member this.StartsWithA = this.StartsWith "A" |
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 inline (>>) f g x = g(f x) | |
| Which reads as: given two functions, f and g, and a value, x, compute the result of f of x and pass that result to g. The interesting thing here is that you can curry the (>>) function and only pass in parameters f and g, the result is a function which takes a single parameter and produces the result g ( f ( x ) ). |
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 memoize f = | |
| let cache = System.Collections.Generic.Dictionary<_,_>(HashIdentity.Structural) | |
| fun x -> | |
| let ok, res = cache.TryGetValue(x) | |
| if ok then res | |
| else let res = f x | |
| cache.[x] <- res | |
| res |
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 Cache (reader: 'key -> 'value) max = | |
| let cache = new Dictionary<'key,LinkedListNode<'key * 'value>>() | |
| let keys = new LinkedList<'key * 'value>() | |
| fun (key : 'key) -> ( | |
| let found, value = cache.TryGetValue key | |
| match found with | |
| |true -> | |
| keys.Remove value | |
| keys.AddFirst value |> ignore |
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.Data.Linq" | |
| open System | |
| open System.Reflection | |
| open System.ComponentModel | |
| open System.Linq.Expressions | |
| open Microsoft.FSharp.Reflection | |
| open Microsoft.FSharp.Quotations | |
| module FSharpType = |
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 DealResult = { | |
| Card : Card option | |
| Deck : Deck | |
| } | |
| let dealACard deck = | |
| match deck with | |
| | [] -> { Card = None; Deck = deck } | |
| | card::restOfDeck -> { Card = Some card; Deck = restOfDeck } |
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 ConstructionAttribute(singleInstance : bool) = | |
| inherit System.Attribute() | |
| member this.IsSingleton = singleInstance | |
| let singletons = new System.Collections.Generic.Dictionary<System.Type,obj>() | |
| let make() : 'a = | |
| let newInstance() = System.Activator.CreateInstance<'a>() | |
| let attributes = typeof<'a>.GetCustomAttributes(typeof<ConstructionAttribute>, true) | |
| let singleInstance = | |
| if attributes.Length > 0 then |
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
| namespace global | |
| open System | |
| open System.Collections.Generic | |
| open System.Linq | |
| open System.Text | |
| open System.Threading.Tasks | |
| open System.IO | |
| open System.Diagnostics | |
| namespace File_Encoder | |
| type Program() = |
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
| namespace global | |
| open System | |
| open System.Collections.Generic | |
| open System.Linq | |
| open System.Text | |
| open System.Threading.Tasks | |
| open System.IO | |
| open System.Diagnostics | |
| namespace File_Encoder | |
| type Encoder() = |