Skip to content

Instantly share code, notes, and snippets.

@maxgherman
maxgherman / ListMonad.cs
Last active January 31, 2019 10:53
C# List Monad
using System;
using System.Collections.Generic;
using System.Linq;
public interface IBox<TClass, out T>
{
TClass Value { get; }
}
public interface IFunctor<F>
@maxgherman
maxgherman / func-compute.ts
Created June 26, 2018 05:13
Typescript functional computations
class Box<F, T> { }
class IsArray {}
interface IFunctor<F> {
fmap<A, B>(f: (a: A) => B, fa: Box<F, A>) : Box<F, B>;
}
@maxgherman
maxgherman / typed-idx.ts
Last active March 14, 2018 02:29
Typed idx
interface IPost {
title: string;
comments?: string[];
}
interface IUser {
posts: IPost[];
}
interface IData {
@maxgherman
maxgherman / immutableArray.ts
Created March 15, 2015 12:21
Typescript immutable array
class ImmutableArray<T> {
private _data : Array<T>;
public get value() : Array<T>{
return this._data.slice(0);
}
constructor(data : Array<T>) {
@maxgherman
maxgherman / getAllPropertyNames.js
Last active August 29, 2015 14:16
Retrieve all property names for JavaScript object including non enumerables
function getAllPropertyNames(obj) {
var props = {};
do {
Object.getOwnPropertyNames(obj).forEach(function (prop) {
if (prop !== 'constructor') {
props[prop] = undefined;
}
});
} while ((obj = Object.getPrototypeOf(obj)) !== Object.prototype);
interface IMessage<T> {
data : T;
}
interface IObserver<T> {
update(message : IMessage<T>) : void;
unregister() : void;
unregisterAction : () => void;
}
@maxgherman
maxgherman / DbSetNSubsituteHelper.cs
Created July 15, 2014 05:49
Entity Framework DbSet NSubsitute Helper
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using NSubstitute;
namespace ConsoleApplication
{
public static class EntityFrameworkHelper
{
public static DbSet<R> AsDbSetSubstitute<R>(this IEnumerable<R> data) where R : class
@maxgherman
maxgherman / InfiniteStreamsCSharp.cs
Last active August 29, 2015 14:03
Haskell / Scala Infinite Streams in C#
using System;
using System.Collections.Generic;
using System.Linq;
namespace ConsoleApplication
{
class Program
{
static void Main(string[] args)