Skip to content

Commit

Permalink
feat(join): Support delimeter as joiner
Browse files Browse the repository at this point in the history
  • Loading branch information
justinvdm committed Apr 30, 2020
1 parent 4d80335 commit 1d441be
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
9 changes: 5 additions & 4 deletions join.js
Expand Up @@ -6,13 +6,14 @@ function join(a, b, c) {
: joinMain(a, b, c)
}

function joinMain(id, joinerFn, makerFns) {
return joinerFn(tuple(id, makerFns))
function joinMain(id, joiner, makerFns) {
var result = tuple(id, makerFns)
return typeof joiner === 'function' ? joiner(result) : result.join(joiner)
}

function joinCurried(joinerFn, makerFns) {
function joinCurried(joiner, makerFns) {
return function joinFn(id) {
return joinMain(id, joinerFn, makerFns)
return joinMain(id, joiner, makerFns)
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/fictional.test.js
Expand Up @@ -11,7 +11,7 @@ const curriedMakerDefs = [
],
[
join,
vals => vals.join(' '),
' ',
[oneOf(['Privet', 'Parkway', 'Cherry']), oneOf(['Drive', 'Street', 'Road'])]
]
]
Expand Down
8 changes: 8 additions & 0 deletions tests/join.test.js
@@ -0,0 +1,8 @@
const tap = require('tap')
const { join } = require('..')

tap.test('function as joiner', t => {
const result = join(23, vals => vals.join(' '), [() => 'a', () => 'b'])
t.equals(result, 'a b')
t.end()
})

0 comments on commit 1d441be

Please sign in to comment.