Skip to content

Commit

Permalink
Fix assocPath depth bug (#17)
Browse files Browse the repository at this point in the history
* Fix assocPath depth bug

* While we're here...

* Build
  • Loading branch information
flintinatux committed Aug 7, 2019
1 parent dc50df3 commit 2081ad2
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
language: node_js
node_js:
- '10'
- '8'
- '7'
- '6'
before_install:
- npm install -g yarn@1.6.0
- npm install -g yarn@1.10.0
install:
- yarn install --pure-lockfile
script:
Expand Down
2 changes: 1 addition & 1 deletion src.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ const assoc = curry((prop, val, obj) => {
})

// assocPath :: [k] -> v -> { k: v } -> { k: v }
const assocPath = curry(([ head, ...tail ], x, obj) =>
const assocPath = curryN(3, ([ head, ...tail ], x, obj={}) =>
assoc(head, length(tail) ? assocPath(tail, x, obj[head]) : x, obj)
)

Expand Down
9 changes: 6 additions & 3 deletions test/assocPath.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ const { assocPath } = require('..')

describe('assocPath', () => {
it('sets a value on a path of a nested object', () =>
expect(assocPath(['foo', 'bar'], 'baz', {})).to.eql({ foo: { bar: 'baz' } })
expect(assocPath(['foo', 'bar', 'bat'], 'baz', {}))
.to.eql({ foo: { bar: { bat: 'baz' } } })
)

it('is curried', () => {
expect(assocPath(['foo', 'bar'])('baz', {})).to.eql({ foo: { bar: 'baz' } })
expect(assocPath(['foo', 'bar'], 'baz')({})).to.eql({ foo: { bar: 'baz' } })
expect(assocPath(['foo', 'bar', 'bat'])('baz', {}))
.to.eql({ foo: { bar: { bat: 'baz' } } })
expect(assocPath(['foo', 'bar', 'bat'], 'baz')({}))
.to.eql({ foo: { bar: { bat: 'baz' } } })
})
})
2 changes: 1 addition & 1 deletion tinyfunk.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2081ad2

Please sign in to comment.