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 associateRels = fixs => attrs => | |
attrs.traverse(Id.of, (attr, name) => | |
name.match(/_id$/) | |
? Id.of(attr.split('.').reduce((acc, p) => acc.get(p), fixs)) | |
: Id.of(attr)) | |
const createRecord = tablename => attrs => | |
Id.of(Object.assign({id: Math.random(2)}, attrs)) |
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
// record is used in place of the actual db row | |
Id({ | |
Band: { | |
dino_jr: record, | |
amanset: record | |
}, | |
Event: { | |
dino_stubbs: record | |
}, | |
Venue: { |
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
makeFixtures(defs) | |
.fork(console.error, console.log) | |
// { | |
// "Band": { | |
// "dino_jr": { | |
// "id": 0.5556986515877327, | |
// "name": "Dinosaur Jr", | |
// "members": 3 | |
// }, | |
// "amanset": { |
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 makeFixtures = defs => | |
Map(defs) | |
.traverse(Id.of, (instances, tablename) => | |
Map(instances).traverse(Id.of, createRecord(tablename))) | |
.chain(fixs => | |
fixs.traverse(Id.of, (instances) => | |
Map(instances).traverse(Id.of, associateRels(fixs)))) |
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: {one: 1}, b: {two: 2}}).traverse(Id.of, (inner, k) => | |
Map(inner).traverse(Id.of, v => Id.of(v + 1))) | |
// Id (Map { "a": Map { "one": 2 }, "b": Map { "two": 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
Map({a: 1, b: 2}).traverse(Id.of, v => Id.of(v + 1)) | |
// Id (Map { "a": 2, "b": 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
makeFixtures(defs).map(fixtures => { | |
// Get the id of the created model | |
fixtures.Band.amanset.id | |
// 3 | |
// Get a relationship | |
fixtures.Event.dino_stubbs.venue.name | |
// Stubbs | |
}) |
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 defs = { | |
Band: { | |
dino_jr: { | |
name: 'Dinosaur Jr', | |
members: 3, | |
}, | |
amanset: { | |
name: 'American Analog Set', | |
members: 7 | |
} |
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 {Left, Right} = require('data.either') | |
const Tuple = require('fantasy-tuples').Tuple2 | |
//List :: Either Null (Tuple a List) | |
const empty = () => | |
Left(null) | |
const cons = (x, l) => | |
Right(Tuple(x, l)) |
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 daggy = require('daggy') | |
const Task = require('data.task') | |
const _ = require('lodash') | |
const kleisli_comp = (f, g) => x => f(x).chain(g) | |
const compose = (f, g) => x => f(g(x)) | |
const id = x => x | |
//=============FREE============= | |
const Free = daggy.taggedSum({Impure: ['x', 'f'], Pure: ['x']}) | |
const {Impure, Pure} = Free |