diff --git a/src/fn.js b/src/fn.js index 7e6ab47..d672e1f 100644 --- a/src/fn.js +++ b/src/fn.js @@ -35,7 +35,7 @@ export const useWith = curry((fn, tfns) => )) export const converge = (fn, tfns) => curryN( - max(map(length, tfns)), + pipe(length, map, max)(tfns), (...args) => fn(...map(tfn => tfn(...args), tfns)) ) @@ -68,7 +68,7 @@ export const split = curry((delim, v) => v.split(delim)) export const max = v => Math.max(...v) export const min = v => Math.min(...v) export const inc = v => v + 1 -export const dec = v => v + 1 +export const dec = v => v - 1 // arrays export const map = curry((fn, v) => v.map(fn)) @@ -103,21 +103,16 @@ export const assocPath = curry((key, value, obj) => pipe( mergeRightDeep(obj), )(key)) -export const mergeLeftDeep = curry((a, b) => { - return reduce((acc, key) => { - const av = acc[key] - const bv = b[key] - - return pipe( - ifElse( - every(is(Object)), - apply(mergeLeftDeep), - last - ), - v => assoc(key, v, acc) - )([av, bv]) - }, a, keys(b)) -}) +export const mergeLeftDeep = curry((a, b) => + reduce((acc, key) => pipe( + ifElse( + every(is(Object)), + apply(mergeLeftDeep), + last + ), + v => assoc(key, v, acc) + )([acc[key], b[key]]), a, keys(b)) +) export const mergeRightDeep = flip(mergeLeftDeep) diff --git a/tests/query.test.js b/tests/query.test.js index 40941c1..8636992 100644 --- a/tests/query.test.js +++ b/tests/query.test.js @@ -29,12 +29,14 @@ describe('query', () => { return eid } - const knows = (a, b) => { - const edge = addEntity(w) - addComponent(w, Knows, edge) - Knows.from[edge] = a - Knows.to[edge] = b - return edge + const relate = (a, type, ...b) => { + return b.map(v => { + const edge = addEntity(w) + addComponent(w, type, edge) + type.from[edge] = a + type.to[edge] = v + return edge + }) } const player = create(Player) // 0 @@ -42,16 +44,10 @@ describe('query', () => { const b = create(NPC) // 2 const c = create(NPC) // 3 - knows(player, a) // 4 - knows(player, c) // 5 - - knows(a, player) // 6 - knows(a, b) // 7 - knows(a, c) // 8 - - knows(b, a) // 9 - - knows(c, player) // 10 + relate(player, Knows, a, c) // 4, 5 + relate(a, Knows, player, b, c) // 6, 7, 8 + relate(b, Knows, a) // 9 + relate(c, Knows, player) // 10 assert.deepEqual( query('MATCH (player:Player) RETURN player', engine).unwrap(),