-
Notifications
You must be signed in to change notification settings - Fork 70
More performant compact map #344
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
972d396
0b3f916
e37b9d5
6472bed
bb1228c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,6 @@ | ||
| # 1.69.1 | ||
| - More performant version of `compactMap`. | ||
|
|
||
| # 1.69.0 | ||
| - Add `isPromise` utility | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,6 +29,17 @@ 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) => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we do a quick benchmark? Lodash supports shortcut fusion which should be effectively the same thing. My first feedback was gonna be to do this with transducers https://runkit.com/daedalus28/transducer-example but lodash does this automatically in some cases - might only be only explicit
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fusion is only supported in the chain scenario. https://lodash.com/docs/4.17.15#lodash |
||
| let fn = _.iteratee(iteratee) | ||
| return _.reduce( | ||
| (acc, x) => { | ||
| let v = fn(x) | ||
| if (v) { | ||
| acc.push(v) | ||
| } | ||
| return acc | ||
| }, | ||
| [], | ||
| collection | ||
| ) | ||
| }) | ||
Uh oh!
There was an error while loading. Please reload this page.