From 972d396bf36995eff3f88d35c2c551a5be6f1cbb Mon Sep 17 00:00:00 2001 From: David Sargeant Date: Mon, 21 Feb 2022 14:12:08 -0500 Subject: [PATCH 1/4] More performant compactMap. --- src/collection.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/collection.js b/src/collection.js index 841ce1da..976dd3e8 100644 --- a/src/collection.js +++ b/src/collection.js @@ -29,6 +29,15 @@ export let insertAtIndex = _.curry((index, val, collection) => : insertAtArrayIndex(index, val, collection) ) -export let compactMap = _.curry((fn, collection) => - _.flow(_.map(fn), _.compact)(collection) -) +export let compactMap = _.curry((iteratee, collection) => { + let fn = _.iteratee(iteratee) + return _.reduce((acc, x) => { + let v = fn(x) + if (v) { + acc.push(v) + } + return acc + }, + [], + collection) +}) From 0b3f9165a5b7af8a187653b620a651c491a7ef2f Mon Sep 17 00:00:00 2001 From: David Sargeant Date: Mon, 21 Feb 2022 14:12:22 -0500 Subject: [PATCH 2/4] Fix Babel. --- package.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/package.json b/package.json index aa76877d..b9e07e9e 100644 --- a/package.json +++ b/package.json @@ -41,8 +41,7 @@ "trailingComma": "es5" }, "devDependencies": { - "babel": "^6.5.2", - "babel-cli": "^6.22.2", + "babel-cli": "^6.26.0", "babel-core": "^6.22.1", "babel-eslint": "^8.0.0", "babel-loader": "^7.0.0", From e37b9d56e33c18c6493f6f7d503eced3439c5af0 Mon Sep 17 00:00:00 2001 From: Decrapifier Date: Mon, 21 Feb 2022 19:17:25 +0000 Subject: [PATCH 3/4] Automagically formatted by Duti! https://github.com/smartprocure/duti --- src/collection.js | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/collection.js b/src/collection.js index 976dd3e8..d28b5d33 100644 --- a/src/collection.js +++ b/src/collection.js @@ -31,13 +31,15 @@ export let insertAtIndex = _.curry((index, val, collection) => export let compactMap = _.curry((iteratee, collection) => { let fn = _.iteratee(iteratee) - return _.reduce((acc, x) => { - let v = fn(x) - if (v) { - acc.push(v) - } - return acc - }, - [], - collection) + return _.reduce( + (acc, x) => { + let v = fn(x) + if (v) { + acc.push(v) + } + return acc + }, + [], + collection + ) }) From 6472bed3dbb2064d592d3deb69571523173db9a5 Mon Sep 17 00:00:00 2001 From: David Sargeant Date: Mon, 21 Feb 2022 14:43:38 -0500 Subject: [PATCH 4/4] Bump version. --- CHANGELOG.md | 3 +++ package.json | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index aa517ac3..f2e1ee6d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +# 1.69.1 +- More performant version of `compactMap`. + # 1.69.0 - Add `isPromise` utility diff --git a/package.json b/package.json index b9e07e9e..12c940c3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "futil-js", - "version": "1.69.0", + "version": "1.69.1", "description": "F(unctional) util(ities). Resistance is futile.", "main": "lib/futil-js.js", "scripts": {