Skip to content
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

feature(#174): add omitIndexes #180

Merged
merged 3 commits into from
Oct 23, 2017
Merged

Conversation

srghma
Copy link
Collaborator

@srghma srghma commented Oct 23, 2017

No description provided.

@srghma srghma force-pushed the feature/omitIndexes branch from 562a6aa to 3af8d6f Compare October 23, 2017 11:51
@char0n
Copy link
Owner

char0n commented Oct 23, 2017

@BjornMelgaard

What about this version ?

const { contains, curry, addIndex, reject } = require('ramda');


// helpers
const rejectIndexed = addIndex(reject);
const containsIndex = curry((indexes, val, index) => contains(index, indexes));

const omitIndexes = curry((indexes, list) => rejectIndexed(containsIndex(indexes), list));

Seems more declarative, easier to read and predicate function creation is hidden inside currying and not exposed to business logic.

@char0n char0n self-requested a review October 23, 2017 13:32
@srghma
Copy link
Collaborator Author

srghma commented Oct 23, 2017

@char0n yes, like it very much

@srghma srghma force-pushed the feature/omitIndexes branch from 2d43ad1 to 299c257 Compare October 23, 2017 13:33
*
* RA.omitIndexes([-1, 1, 3], ['a', 'b', 'c', 'd']); //=> ['a', 'c']
*/

Copy link
Owner

@char0n char0n Oct 23, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pls move rejectIndexed and containsIndex before the jsdoc to that jsdoc is applied directly to omitIndexes and not to rejectIndexed.

const expected = ['a', 'c'];

eq(RA.omitIndexes(indexes, arr), expected);
});
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pls add tests for 3 more usecases:

  • empty indexes (will return unmodified list)
  • empty list (will return empty list)
  • combination of empty list and empty indexes

Just to be sure we have corner cases covered. I will adjust pickIndexes in #181 to be consistent with your omitIndexes.

Then we can merge.

@srghma
Copy link
Collaborator Author

srghma commented Oct 23, 2017

@char0n done

src/index.d.ts Outdated
* Returns a partial copy of an array omitting the indexes specified.
*/
omitIndexes<T>(indexes: number[], list: Array<T>): Array<T>;
omitIndexes(indexes: number): <T>(list: Array<T>) => Array<T>;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be indexes: number[] ?

*
* @func omitIndexes
* @memberOf RA
* @since {@link https://char0n.github.io/ramda-adjunct/1.18.1|v1.18.1}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're at 1.19.0. You can always find the next version inside package.json.

@srghma srghma force-pushed the feature/omitIndexes branch from 5f2b439 to da41285 Compare October 23, 2017 19:15
@srghma
Copy link
Collaborator Author

srghma commented Oct 23, 2017

@char0n done

Copy link
Owner

@char0n char0n left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nicely done

@srghma
Copy link
Collaborator Author

srghma commented Oct 23, 2017

@char0n thanks)

@char0n char0n merged commit d65a42d into char0n:master Oct 23, 2017
srghma pushed a commit to srghma/ramda-adjunct that referenced this pull request Jan 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants