Skip to content

Commit

Permalink
feat(concat): implement concatAF method
Browse files Browse the repository at this point in the history
  • Loading branch information
ScottRudiger committed May 22, 2018
1 parent 47c2dea commit b7fbf43
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lib/methods/arrays/concatAF.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/* eslint-disable no-confusing-arrow */
const concatAF = function (...values) {
return this.then(arrOrStr => {
if (!(typeof arrOrStr === 'string' || Array.isArray(arrOrStr))) throw TypeError(
`concatAF cannot be called on ${arrOrStr}, only on an Array or String`,
);
return values.reduce((arrOrStr, value) =>
value instanceof this.constructor || value instanceof Promise
? value.then(value => arrOrStr.concat(value))
: arrOrStr.concat(value), arrOrStr);
});
};

export default concatAF;
6 changes: 6 additions & 0 deletions packageList.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import findIndexAF from './lib/methods/arrays/findIndexAF';
import indexOfAF from './lib/methods/arrays/indexOfAF';
import lastIndexOfAF from './lib/methods/arrays/lastIndexOfAF';
import joinAF from './lib/methods/arrays/joinAF';
import concatAF from './lib/methods/arrays/concatAF';

const arrayMethods = [
name(mapAF, 'mapAF'),
Expand All @@ -62,6 +63,7 @@ const arrayMethods = [
name(indexOfAF, 'indexOfAF'),
name(lastIndexOfAF, 'lastIndexOfAF'),
name(joinAF, 'joinAF'),
name(concatAF, 'concatAF'),
].map(method => [
method,
`${libPath}methods/arrays/${method.name}`,
Expand All @@ -72,7 +74,11 @@ const arrayMethods = [
import splitAF from './lib/methods/strings/splitAF';

const stringMethods = [
name(includesAF, 'includesAF'),
name(indexOfAF, 'indexOfAF'),
name(lastIndexOfAF, 'lastIndexOfAF'),
name(splitAF, 'splitAF'),
name(concatAF, 'concatAF'),
].map(method => [
method,
`${libPath}methods/strings/${method.name}`,
Expand Down

0 comments on commit b7fbf43

Please sign in to comment.