Skip to content

Commit

Permalink
groupoid supports circular references
Browse files Browse the repository at this point in the history
  • Loading branch information
sadasant committed Mar 19, 2017
1 parent eb86aa6 commit a1f9ff2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ export const groupoid = (...funs) => function G (
// Optional parameters
acc = [], // accumulator
breadth, // breadth first is falsy by default
orientation = 1, // > 0 by default, goes bottom to top if < 0
path = [] // only used for recursion purposes
orientation = 1, // > 0 by default, goes bottom to top if < 0 // TODO: Expose a groupoidRight to make this easier
path = [] // only used for recursion purposes, to expose the parent keys of the current key value pair
) {
// return the current accumulator if the field is not iterable
if (!field || typeof field !== 'object') return acc
Expand Down
8 changes: 8 additions & 0 deletions test/algebras.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,14 @@ describe('Algebras', () => {
expect(f.groupoid(reducer)(numbers)).to.deep.equal(_.reduce(reducer)([], numbers))
})

it('groupoid follows circular references as they are', () => {
let reducer = (a, b, k) => b === true ? a.concat(a.length) : a
let stopAtTen = a => a.length < 10
let circular = { count: true }
circular.circular = circular
expect(f.groupoid(reducer, stopAtTen)(circular)).to.deep.equal([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ])
})

it('groupoid for variable accumulator', () => {
// Count until
expect(f.groupoid(acc => acc < 3, acc => ++acc)([ 1, 2, 3, 4 ], 0)).to.equal(3)
Expand Down

0 comments on commit a1f9ff2

Please sign in to comment.