Skip to content

Instantly share code, notes, and snippets.

Matthew Podwysocki mattpodwysocki

Block or report user

Report or block mattpodwysocki

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View MapReduce WordCount
#light
namespace Microsoft.MapReduce
[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
[<CompilationMapping(SourceConstructFlags.Module)>]
module String =
open System.Text.RegularExpressions
let words (s:string) : string list =
View gist:54622
#light
type ICustomerRepository =
abstract GetCustomersWithFirstNameOf : string -> seq<Customer>
let test_lookup() =
let repository = { new ICustomerRepository with
member this.GetCustomersWithFirstNameOf(name) =
[{ CustomerName = name; Address = "1 Microsoft Way"; City = "Redmond"; State = "WA" }]
}
View gist:61874
#light
namespace CodeBetter.Extensions
[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
[<CompilationMapping(SourceConstructFlags.Module)>]
module List =
// Insert
// The non-overloaded version of 'insert'
View gist:62502
#light
open System
module List =
let to_string (xs:char list) : string =
new string(Array.of_list xs)
module Char =
View gist:67313
#light
module Char =
open System
let isAlpha = Char.IsLetter
let isDigit = Char.IsDigit
let isHexDigit c =
View gist:69880
public static IEnumerable<T> Filter<T>(this IEnumerable<T> items, Func<T, bool> pred)
{
return items.Aggregate<T, Func<IEnumerable<T>, IEnumerable<T>>>(
x => x, (f, c) => x => f(pred(c) ? (new [] { c }).Concat(x) : x))(Enumerable.Empty<T>());
}
public static IEnumerable<R> Map<T, R>(this IEnumerable<T> items, Func<T, R> proj)
{
return items.Aggregate<T, Func<IEnumerable<R>, IEnumerable<R>>>(
x => x, (f, c) => x => f((new[] { proj(c) }).Concat(x)))(Enumerable.Empty<R>());
View gist:73041
[Fact]
public void TestSpecificationCollection()
{
var minCredit = 3;
var product = new Product() { MinimumCreditRating = minCredit, Price = 50 };
var spec = new EligibleForDiscountSpecification(product);
var customers = new List<Customer>()
{
new Customer() {CreditRating = minCredit-2}, // bad credit
View gist:76001
-- Haskell
identity :: [a] -> [a]
identity xs = foldr (:) [] xs
// F#
let identity (xs:'a list) : 'a list = List.fold_right (::) [] xs;;
View gist:81221
-- Haskell
fibs = 0 : 1 : zipWith (+) fibs (tail fibs)
// F#
let rec fibs : LazyList<int> =
LazyList.cons 0 (LazyList.cons 1 (fun() -> (LazyList.map2 (+) fibs (LazyList.tl fibs))))
View gist:82459
-- Haskell
(.) :: (b -> c) -> (a -> b) -> a -> c
// F#
val (<<) : ('a -> 'b) -> ('c -> 'a) -> 'c -> 'b
val (>>) : ('a -> 'b) -> ('b -> 'c) -> 'a -> 'c
val (|>) : 'a -> ('a -> 'b) -> 'b
val (<|) : ('a -> 'b) -> 'a -> 'b
You can’t perform that action at this time.