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
private static IEnumerable<UnionVisitor<TQuerySource>.UnionExpression> GetUnionExpressions(Expression expression) | |
{ | |
Func<Expression, IEnumerable<UnionVisitor<TQuerySource>.UnionExpression>> getVisitorExpressions = x => | |
{ | |
var unionVisitor = new UnionVisitor<TQuerySource>(); | |
unionVisitor.Visit(x); | |
return unionVisitor.Expressions; | |
}; | |
return GetUnionExpressions(getVisitorExpressions(expression), getVisitorExpressions); | |
} |
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 GetUnionExpressions<'a> expression = | |
let getVisitorExpressions expression = | |
let unionVisitor = new UnionVisitor<'a>() | |
unionVisitor.Visit(expression : Expression) |> ignore | |
unionVisitor.Expressions | |
let rec getUnionExpressions (expressions : seq<UnionVisitor<'a>.UnionExpression>) = | |
if expressions |> Seq.isEmpty then Seq.empty | |
else expressions |
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
public abstract class ExpressionVisitorBase<TState> | |
{ | |
public class ExpressionNotSupportedException : Exception | |
{ | |
public ExpressionNotSupportedException(Expression expression) : | |
base(string.Format("Expression {0} not supported.", expression.GetType().Name)) { } | |
} | |
public virtual TState Visit(Expression node) | |
{ |
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
"Sometimes the only way you can feel good about yourself is by making someone else look bad. And I'm tired of making other people feel good about themselves." ~Homer J Simpson |
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
require "fileutils" | |
module FileSystem | |
def FileSystem.EnsurePath(path) | |
if !Dir.exists?(path) then | |
FileUtils.mkdir_p(path) | |
end | |
end |
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
public static class MaybeMonadicExtensions | |
{ | |
public static Maybe<T> ToMaybe<T>(this T value) | |
{ | |
return value == null ? Maybe.Nothing<T>() : Maybe.Just(value); | |
} | |
public static Maybe<B> Bind<A, B>(this Maybe<A> a, Func<A, Maybe<B>> func) | |
{ | |
return a.HasValue ? func(a.Value) : Maybe.Nothing<B>(); |
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
// http://stevesmithblog.com/blog/how-do-i-use-structuremap-with-asp-net-mvc-3/ | |
return _container.GetAllInstances<object>().Where(s => s.GetType() == serviceType); | |
// Isn't this a better way to do it? | |
return _container.GetAllInstances(serviceType).Cast<object>(); |
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
// Some function | |
Func<int, int, int, int> multiplyThree = (a, b, c) => a * b * c; | |
// Lets curry it by breaking it up into multiple functions that only have one arg | |
Func<int, Func<int, Func<int, int>>> multiplyThreeCurried = (a) => (b) => (c) => multiplyThree(a, b, c); | |
// This is curried, yay! | |
var result = multiplyThreeCurried(10)(2)(3); | |
// This is partially applied |
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
public static IEnumerable<object> GetAllInstances(this IContainer container, IEnumerable<Type> types) | |
{ | |
return container.Model.AllInstances. | |
Join(types, x => x.PluginType, y => y, (x, y) => x). | |
Select(x => x.ConcreteType). | |
Distinct(). | |
Select(container.GetInstance); | |
} |
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
// This one liner: | |
return GetState().Map(x => x.ContainsKey(key) ? x[key] : null); | |
// Instead of this multiliner | |
var state = GetState(); | |
return state.ContainsKey(key) ? state[key] : null; |