Skip to content

Instantly share code, notes, and snippets.

@jemgold
Created March 1, 2016 08:21
Show Gist options
  • Save jemgold/0e171d51e241a745fe07 to your computer and use it in GitHub Desktop.
Save jemgold/0e171d51e241a745fe07 to your computer and use it in GitHub Desktop.
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