Skip to content

Instantly share code, notes, and snippets.

View jethrolarson's full-sized avatar
:shipit:

Jethro Larson jethrolarson

:shipit:
  • Tableau
  • Seattle
View GitHub Profile
@jethrolarson
jethrolarson / test.util.js
Last active December 10, 2016 01:19
An alternative to using beforeEach and afterEach
const I = a => a
// this is just wrapping before and after functions around chai's BDD `it`
export const wrapIt = (before = I, after = I) => (label, fn) => {
const ctx = before();
it(label, (ctx) => fn.call(ctx));
after(ctx);
};
[alias]
staged = diff --staged
br = branch
st = status
co = checkout
cod = checkout develop
md = merge develop
cb = checkout --track -b
ci = commit
ca = commit --amend
@jethrolarson
jethrolarson / README.md
Last active August 29, 2016 18:45
Functional Dependency Injection in JavaScript

Dependency Inversion Principle (DIP) is a design pattern popular in Object Oriented Programming but it's not alien to functional programming. Parameterizing dependencies is actually critical to maintaining functional purity--one of the most important aspects of FP.

While special dependency injection frameworks are sometimes used, a similar effect can be achieved using partial application.

// There's something elegant about this...
const foo = (bar, baz) => Object.assign({}, baz, {bar})
We couldn’t find that file to show.
@jethrolarson
jethrolarson / .eslintrc.yml
Last active March 8, 2016 02:01
FP eslint
---
extends: "eslint:recommended"
root: true
env:
es6: true
browser: true
node: true
ecmaFeatures:
modules: false
rules:
var FT = require('myFunctionalTestFramework');
module.exports = FT.suite("Array", {
"is a functor": (it)=> {
var ar = [1]
return it.all(
it('returns array with value incremented').isLike([2], ar.map(x=>x+1))
, it('returns new array').isnt(ar, ar.map(a => a))
)
}
})
// Similar to Future but contains a series of future values
const {I, compose} = require('../util')
// ( -> a) -> Stream a
function _Stream(pusher) {
this.push = pusher || I
this['@@type'] = "Stream"
}
const Stream = pusher => new _Stream(pusher)
@jethrolarson
jethrolarson / _usage.js
Last active April 25, 2016 01:10
xface - Functional Interface library for typed common apis
//Some fantasy implementations
const Just = require('./just')
const Cant = require('./cant')
const List = require('./list')
//Spec file that defines what arguments are used for type identification
const fantasy = require('./fantasy')
//The magic.
const {chain, map, index} = require('../../src/xface')(fantasy, [Just, Cant])
@jethrolarson
jethrolarson / exampleUsage.js
Last active June 26, 2016 21:05
AGeneric interface fantasy-land objects
var Maybe = require('./maybe.js')
var List = require('./list.js')
//Pass fantasy implementations to it
var {concat, map} = require('fantasy')({Maybe, List})
mapDouble = map(a => 2 * a)
mapDouble([1, 2])
//[2, 4]