Skip to content

Commit

Permalink
Merge 50d98ae into dc50df3
Browse files Browse the repository at this point in the history
  • Loading branch information
flintinatux committed Aug 7, 2019
2 parents dc50df3 + 50d98ae commit c89461c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
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' } } })
})
})

0 comments on commit c89461c

Please sign in to comment.