This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Components = [‘alert’, ‘buttons’, ‘data-tables’, /* …etc */] | |
// build a Map of just {key: key} | |
const empty = Components.reduce((acc, key) => acc.set(key, key), Immutable.Map()) | |
// load up each component | |
const ui = empty.map(loadComponent).map(addExample).map(beautifyHtml).map(addSelectorTable) | |
// access a component | |
ui.get(‘buttons’) // { "name": "Buttons", "example": Maybe.Just(Task), "html": Maybe.Just(<some html>), "selectors": Maybe.Just(cols,rows) } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const UI = Immutable.Map({ | |
‘alerts’: {/* lots of stuff */}, | |
‘buttons’:{/* lots of stuff */}, | |
‘data-tables’: {/* lots of stuff */} | |
// lots more components | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Immutable = require('immutable-ext') | |
const {Just, Nothing} = require('data.maybe') | |
const Task = require('data.task') | |
// Setup | |
const Reader = f => | |
({ | |
run: f, | |
map: g => Reader(x => g(f(x))), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const {Tuple} = require('fantasy-tuples') | |
const Either = require('data.either') // missing extend, but could pr | |
Tuple(current_user, age) | |
.map(age => age + 1) | |
.extend(({_1: user, _2: age}) => | |
Object.assign({}, user, {age})) | |
// Tuple(current_user, current_user_with_age) | |
// ^ notice this only ever changes the _2, but you can see _1 while you work. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const {Map} = require('immutable-ext') | |
const Id = require('fantasy-identities') | |
const Task = require('data.task') | |
const defs = { | |
Band: { | |
dino_jr: { | |
name: 'Dinosaur Jr', | |
members: 3, | |
}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// to, from are awkward here. generateReport only needs them to send an email | |
const generateReport = (to, from, data) => | |
mungeData(data, (warnings, munged) => | |
renderReport(munged, (report) => emailReport(to, from, report))) | |
generateReport(“info@reports.com”, “app@test.net”, {some: ‘data’}) | |
// if emailReport was curried, we could pass in the emailer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function add1(v) { return v + 1; } | |
function isOdd(v) { return v % 2 == 1; } | |
function sum(total,v) { return total + v; } | |
function listReduction(list,v) { | |
list.push(v); | |
return list; | |
} | |
function mapReducer(fn) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"Band": { | |
"dino_jr": { | |
"id": 0.5933238949411739, | |
"name": "Dinosaur Jr", | |
"members": 3 | |
}, | |
"amanset": { | |
"id": 0.9872892555359196, | |
"name": "American Analog Set", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Map({a: 1, b: 2}).map(v => Id.of(v + 1)) | |
// Map { "a": Id(2), "b": Id(3) } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const createRecord = tablename => attrs => | |
Id.of(Object.assign({id: Math.random(2)}, attrs)) | |
const makeFixtures = defs => | |
Map(defs) | |
.traverse(Id.of, (instances, tablename) => | |
Map(instances).traverse(Id.of, createRecord(tablename))) |