Skip to content

Commit

Permalink
assignP
Browse files Browse the repository at this point in the history
  • Loading branch information
pklingem committed Jan 30, 2018
1 parent f2d8f05 commit 47cd1b7
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions index.js
@@ -1,5 +1,6 @@
exports.all = require('./lib/all')
exports.assign = require('./lib/assign')
exports.assignP = require('./lib/assignP')
exports.backoff = require('./lib/backoff')
exports.combine = require('./lib/combine')
exports.combineAll = require('./lib/combineAll')
Expand Down
9 changes: 9 additions & 0 deletions src/assignP.js
@@ -0,0 +1,9 @@
const curry = require('ramda/src/curry')
const combineWithP = require('./combineWithP')
const put = require('./put')

// assignP : String -> ({ k: v } -> Promise a) -> Promise { k: v }
const assignP = (key, fn) =>
combineWithP(put(key), fn)

module.exports = curry(assignP)
19 changes: 19 additions & 0 deletions test/assignP.js
@@ -0,0 +1,19 @@
const { expect } = require('chai')
const property = require('prop-factory')
const always = require('ramda/src/always')

const { assignP } = require('..')

const assigner = assignP('foo', always(Promise.resolve('bar')))

describe('assignP', () => {
const res = property()

beforeEach(() =>
assigner({}).then(res)
)

it('sets the foo property to the result of the function', () =>
expect(res()).to.eql({ foo: 'bar' })
)
})

0 comments on commit 47cd1b7

Please sign in to comment.