Skip to content

Commit

Permalink
Add partialRight
Browse files Browse the repository at this point in the history
  • Loading branch information
flintinatux committed Jan 26, 2018
1 parent f26566f commit 04ab036
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,11 @@ const omit = curry((keys, obj) => {
// partial : (a... -> b) -> [a] -> a... -> b
const partial = curry(_partial)

// partialRight : (a... -> b) -> [a] -> a... -> b
const partialRight = curryN(3, (f, right, ...left) =>
apply(f, concat(left, right))
)

// path : [k] -> { k: v } -> v
const path = curry(([ head, ...tail ], obj) =>
length(tail) ? path(tail, obj[head]) : obj[head]
Expand Down Expand Up @@ -354,6 +359,7 @@ module.exports = {
objOf,
omit,
partial,
partialRight,
path,
pick,
pipe,
Expand Down
16 changes: 16 additions & 0 deletions test/partialRight.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const { expect } = require('chai')

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

describe('partialRight', () => {
const sum = (a, b, c, d) =>
a + b * c + d

it('partially applies right-side args to a function', () =>
expect(partialRight(sum, [ 1, 2 ])(3, 4)).to.equal(9)
)

it('is curried', () =>
expect(partialRight(sum)([ 1, 2 ])(3, 4)).to.equal(9)
)
})
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 04ab036

Please sign in to comment.