Skip to content

Instantly share code, notes, and snippets.

Avatar

Alexander Shvedov controlflow

View GitHub Profile
View gist:8380121
class Program
{
// What argument do you need to provide to this method so that it returns true?
public static bool AreYouNuts<T>(T[] array)
{
if (array == null || array.Length == 0)
return false;
var local = (T[]) array.Clone();
@controlflow
controlflow / gist:7846397
Last active Dec 30, 2015
Boolean solver via C# overload resolution
View gist:7846397
static class BooleanSolver {
class T {
public static T operator |(T x, T y) => null;
public static T operator |(T x, F y) => null;
public static T operator &(T x, T y) => null;
public static F operator &(T x, F y) => null;
public static F operator !(T x) => null;
}
class F {
@controlflow
controlflow / gist:7804901
Created Dec 5, 2013
How C# lambdas with a single ref-type immutable closure can be optimized
View gist:7804901
using System;
static class LiftingClosureToDelegateTarget {
static void Main() {
// normal lambda
{
var str = GetString();
Func<string> f = () => str;
Console.WriteLine(f());
}
@leppie
leppie / gist:6935622
Created Oct 11, 2013
C# COMPILER, Y U MAKE ME SO MUCH CODE WHEN YOU SHOULD KNOW BETTER?
View gist:6935622
#if DEBUG
public static XYZ Normalize(this XYZ c, [CallerMemberName] string caller = "")
#else
public static XYZ Normalize(this XYZ c)
#endif
{
#if DEBUG // completely needless
Debug.Print("normalizing: {0} called from: {1}", c, caller);
#endif
return new XYZ
@yevhen
yevhen / gist:5199613
Created Mar 19, 2013
The concept of message handling Component and the example of message handler chaining via functional composition
View gist:5199613
/* somewhere in your Core.CQRS */
// Base class for all ES-based aggregate command handling components;
//
// NOTE: "Component" is a logical grouping of message handlers by function
// They provide good place to encapsulate chaining of cross-cutting concerns
// into a pipeline, providing simplified helper methods for registration of message handlers
//
// Components are similar to Services, thus they only contain handlers of single type (ie Command Handlers only)
// Components operate on envelope (infrastructure) level