Skip to content

Instantly share code, notes, and snippets.

@loosechainsaw
loosechainsaw / gist:845af3f55b59f0442f7a
Created July 15, 2014 06:07
csharp monadic styles
public interface IMaybe<T>
{
IMaybe<U> Fmap<U>(Func<T,U> apply);
IMaybe<U> Bind<U>(Func<T,IMaybe<U>> apply);
IMaybe<V> Bind<U, V>(Func<T, IMaybe<U>> func, Func< U, V> map);
void Foreach(Action<T> action);
U Fold<T,U> (Func<T,U> some, Func<U> none);
}
public static class MaybeExtensions
@loosechainsaw
loosechainsaw / wipesf.cs
Created June 30, 2014 01:30
WIP CQRS ES Framework
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.IO;
using System.Reactive.Linq;
using System.Reactive.Concurrency;
namespace Alchemy.Framework
{
@loosechainsaw
loosechainsaw / cspermgen.cs
Created June 28, 2014 15:16
C# Permutation Generator
using System;
using System.Collections.Generic;
using System.Linq;
using System.Collections;
using System.Text;
namespace CSharpPermutations
{
public interface IPermutable<T>
@loosechainsaw
loosechainsaw / expression_template_ex.cpp
Created June 10, 2014 14:47
Classic Vector as Expression Template
#include <iostream>
namespace stdextensions
{
template<class T, size_t N>
class array_rep{
public:
array_rep() = default;
array_rep(array_rep const& ) = default;
@loosechainsaw
loosechainsaw / lamebtree.hs
Created May 26, 2014 14:48
Lame Binary Tree in Haskell
module Main where
data List a = Nil | Cons a (List a)
deriving (Show)
data Tree a = Empty | Node a (Tree a) (Tree a)
deriving (Show)
append :: (Ord a) => Tree a -> a -> Tree a
append Empty a = Node a (Empty) (Empty)
@loosechainsaw
loosechainsaw / appendSwapped.hs
Last active August 29, 2015 14:01
appendSwapped.hs
module Main where
appendSwapped :: [(a,a)] -> [(a,a)]
appendSwapped [] = []
appendSwapped xs = xs ++ (flipped xs)
where flipped li = foldr (\c d -> swaptuple c : d ) [] li
swaptuple (a,b) = (b,a)
main :: IO ()
main = print $ appendSwapped [(1,2), (3,4)]
@loosechainsaw
loosechainsaw / splitat.hs
Created May 7, 2014 13:31
Haskell Implementation of Split At
seperateAt :: Int -> [a] -> ([a],[a])
seperateAt 0 [] = ([], [])
seperateAt 0 xs = ([], xs)
seperateAt n (x: []) = (x : [], [])
seperateAt n (x:xs) =
let result = (seperateAt (n - 1) xs)
in (x : fst result, snd result)
#include <iostream>
#include <memory>
template<class T>
class Option{
public:
Option() : value_(nullptr){
}
Option(T const& value) : value_(std::move(value)){
#ifndef DRAWING
#define DRAWING
#include <memory>
#include <iostream>
namespace concepts{
namespace drawing{
struct concept_t{
concept_t() = default;
#include <iostream>
#include <vector>
#include <memory>
#include <algorithm>
class drawable_concept{
public:
drawable_concept() = default;
virtual ~drawable_concept() = default;
drawable_concept(drawable_concept const&) = delete;