Skip to content

Instantly share code, notes, and snippets.

View jethrolarson's full-sized avatar
:shipit:

Jethro Larson jethrolarson

:shipit:
  • A MAJOR ONE
  • Seattle
View GitHub Profile
// 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)
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))
)
}
})
@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:
We couldn’t find that file to show.
// There's something elegant about this...
const foo = (bar, baz) => Object.assign({}, baz, {bar})
@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.

[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 / 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);
};
@jethrolarson
jethrolarson / createClass.jsx
Created December 14, 2016 21:31
Bind all solutions
import React, {createClass} from 'react';
class MediaLibrary = createClass({
foo() {
this.setState({foo: !this.state.foo})
},
render() {
return (<Bar onFoo={this.foo} />);
}
}
@jethrolarson
jethrolarson / index.js
Created January 4, 2017 18:41
Loop fusion with transducers in Ramda
import {into, pipe, filter, map, propEq, prop} from 'ramda';
const doStuff = pipe(
filter(propEq('status', 'active')),
map(prop('age'))
);
// only iterates array once
into([], doStuff, [{status: 'active', name: 'Pam'}, {status: 'bad', name: 'Mancy'}]);
// ['Pam']