Skip to content

Instantly share code, notes, and snippets.

@TGOlson
TGOlson / finder.hs
Created June 2, 2015 20:29
Finder Monoid
import Data.Monoid
import Data.Maybe
import Data.List
data Finder a = Finder ([a] -> Maybe a)
instance Monoid (Finder a) where
mempty = Finder (const Nothing)
@TGOlson
TGOlson / update-tenant-auth-connectors.js
Last active August 29, 2015 14:21
Update tenant auth connectors migration
/*
* Generate migration file:
* $ gulp create-migration --name update-tenant-auth-connectors
*/
// Define migration
var systemService = require('<systemService>'),
systemTenant = systemService.systemTenant;
exports.up = Scaffold.defineMigration(function() {
@TGOlson
TGOlson / rpn.js
Last active August 29, 2015 14:20
Functional RPN Calc
var R = require('ramda');
var rpn = R.compose(R.head, R.reduce(foldingFn, []), R.split(' '));
function foldingFn(acc, v) {
if(isOperator(v)) {
var vs = R.take(2, acc),
rest = R.drop(2, acc);
return R.prepend(useOperator(v, vs), rest);
@TGOlson
TGOlson / list.hs
Last active August 29, 2015 14:19
Custom List Data Type WIP
data List a = Empty | Cons a (List a) deriving (Eq)
instance Show a => Show (List a) where
show list = "(" ++ showListContents list ++ ")"
showListContents :: Show a => List a -> String
showListContents Empty = ""
showListContents (Cons x Empty) = show x
@TGOlson
TGOlson / monoid-factory.js
Last active August 29, 2015 14:19
Monoid factory
'use strict';
var R = require('ramda');
var extract = R.invoke('extract', []);
var makeMonoid = R.curry(function(identity, binary, v) {
@TGOlson
TGOlson / all_monoid.js
Created April 25, 2015 19:35
All as a monoid
'use strict';
// All (||) operator as a monoid
function All(v) {
return {
value: v
};
}
@TGOlson
TGOlson / or_monoid.js
Last active August 29, 2015 14:19
Or operator as a monoid
'use strict';
// Or (||) operator as a monoid
function Or(v) {
return {
value: v
};
}
@TGOlson
TGOlson / binary_search_tree.js
Created April 6, 2015 06:59
Binary Search Tree
/**
* Data Type
*/
// Tree a = EmptyTree | Node a (Tree a) (Tree a)
/**
* Value Constructors
*/
@TGOlson
TGOlson / property-getter.js
Created March 23, 2015 02:38
PropertyGetter monad kata
function PropertyGetterFactory(value) {
return {
get: function(prop) {
return mapToPropertyGetter(partial(get, prop), value);
},
map: function(callback) {
return mapToPropertyGetter(callback, value);
},
unwrap: always(value)
};
@TGOlson
TGOlson / graph_utils.js
Last active August 29, 2015 14:17
Graph utility with property getter monad
var R = require('ramda');
// [k] -> {k: a, load: fn} -> a
var getPath = R.curry(function(propList, entity) {
return getPathFromPropList(propList, entity);
});
var getPathFromPropList = R.curry(function(propList, entity) {
var loadPattern = convertPropListToLoadPattern(propList);