Skip to content

Instantly share code, notes, and snippets.

Brian Lonsdorf DrBoolean

Block or report user

Report or block DrBoolean

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@DrBoolean
DrBoolean / fp_arch.js
Last active May 17, 2019
OO => FP architecture refactor
View fp_arch.js
// Simple example, but the idea holds for more complex objects.
/* 1) Start with OO */
// user.js
class User {
constructor(firstName, lastName, email) {
this.firstName = firstName
this.lastName = lastName
@DrBoolean
DrBoolean / three_envs.js
Last active Apr 3, 2019
Tail of three envs
View three_envs.js
const compose = (f, g) => x => f(g(x))
const Id = x =>
({
fold: f => f(x),
map: f => Id(f(x))
})
Id.of = Id
const Tuple = (_1, _2) =>
View rep10.js
// build the empty ui data structure
const empty = from(x => x)
// a function that returns a complete component instead of a map that loops through all
const ui = Reader(to(empty)).map(loadComponent).map(addExample).map(beautifyHtml).map(addSelectorTable)
// run the function for a component
ui.run(‘buttons’) // {name: ‘Button’, example: ReactElement}
View rep9.js
const Reader = f =>
({
 run: f,
 map: g => Reader(x => g(f(x))),
 chain: g => Reader(x => g(f(x)).run(x))
})
Reader.of = x => Reader(() => x)
// function application
View rep8.js
// create an empty ui
const empty = from(x => x)
// make a function to get the loaded up component
const ui = to(empty).map(loadComponent).map(addExample).map(beautifyHtml).map(addSelectorTable)
// run the function on the index we want
ui(‘buttons’) // {name: ‘Button’, example: ReactElement}
View rep7.js
// create empty ui
const empty = Components.reduce((acc, key) => acc.set(key, key), Immutable.Map())
// load every component with every example and data filled in
const ui = empty.map(loadComponent).map(addExample).map(beautifyHtml).map(addSelectorTable)
// get the componet we want for the page
ui.get(‘buttons’) // {name: ‘Button’, example: ReactElement}
View rep6.js
const Components = [‘alert’, ‘buttons’, ‘data-tables’, /* …etc */]
// from :: (Component -> a) -> UI
const from = f =>
 Components.reduce((ui, key) => ui.set(key, f(key)), Immutable.Map())
// to :: UI -> (Component -> a)
const to = structure =>
 key => structure.get(key)
View rep5.js
const Pair = (x, y) =>
({
 _0: x,
 _1: y,
 map: f => Pair(x, f(y))
})
// to :: Pair a -> (Bool -> a)
const to = ({_0, _1}) =>
 bool => bool ? _0 : _1
View rep4.js
const Id = x =>
({
 x,
 map: f => Id(f(x))
})
// to :: Id a -> (() -> a)
const to = ({x}) => () => x
// from :: (() -> a) -> Id a
View rep3.js
const UI = {
 ‘alerts’: undefined,
 ‘buttons’:{/* lots of stuff */},
 ‘data-tables’: undefined
}
You can’t perform that action at this time.