Skip to content

Commit

Permalink
feat(Modules): Add defer
Browse files Browse the repository at this point in the history
  • Loading branch information
beardedtim committed Sep 17, 2017
1 parent 83f8164 commit 44f9620
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
19 changes: 19 additions & 0 deletions __tests__/modules/defer.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import defer from '../../modules/defer'

describe('defer', () => {
test('returns a function that applies the arguments to the given function', () => {
const fn = (a, b, c) => a + b + c
const args = [1, 2, 3]
const result = defer(args, fn)

expect(result()).toBe(6)
})

test('is curried', () => {
const fn = (a, b, c) => a + b + c
const args = [1, 2, 3]
const result = defer(args)(fn)

expect(result()).toBe(6)
})
})
5 changes: 5 additions & 0 deletions modules/defer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import curry from './curry'

const defer = curry((args, fn) => () => fn.apply(null, args))

export default defer

0 comments on commit 44f9620

Please sign in to comment.