Created
March 1, 2016 08:21
-
-
Save jemgold/0e171d51e241a745fe07 to your computer and use it in GitHub Desktop.
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
import { StyleMatrix, Style, StyleProp } from './Types'; | |
import { addIndex, assoc, concat, keys, map, prop, reduce } from 'ramda'; | |
const reduceIndexed = addIndex(reduce); | |
function product([head, ...tail]) { | |
if (head === undefined) { return [[]]; } | |
const prod = product(tail); | |
return reduce((mem, x) => { | |
return concat(mem, map((p: Array<any>) => { | |
return [x, ...p]; | |
}, prod)); | |
}, [], head); | |
} | |
export default function solve(matrix: StyleMatrix): Array<Style> { | |
const ks = keys(matrix); | |
const vs = map((key: string) => prop(key, matrix), ks); | |
console.log(ks, vs); | |
return map((prodResult: Array<StyleProp>) => { | |
return reduceIndexed((memo: Object, k: StyleProp, i: number) => { | |
return assoc(k, prodResult[i], memo); | |
}, {}, ks); | |
}, product(vs)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment