-
Notifications
You must be signed in to change notification settings - Fork 30
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
Add 'add_row_if' and 'add_rows_if' methods #106
Conversation
Is there anything blocking this PR? Is there anything I can do to push this forward @Nukesor? |
Hey :) Sorry for being so slow to respond. I'm currently super busy and I rarely find time to maintain my open source projects. This will hopefully change in a week or so. We got some public holiday coming up this weekend, so I might get a bit of time to review a few things :) |
I think this could be neat, but I don't like that the fact that the predicate doesn't take any parameters at all. What do you think about the following to make this a bit more useful: |
Yeah I was thinking the same thing, the predicate doesn't do much at the moment. I was also thinking about passing in some kind of "context". I like the idea of passing in row information! I will look into it and will update this PR accordingly. |
The closure function now provides the current row index and a reference to all rows as parameters accessible inside the closure body.
I updated the closure function signature from Fn() -> bool to Fn(usize, &Vec<Row>) -> bool Users now have access the the current row index and all previously added rows. Let me know, if these parameters make sense. |
Can we move forward with these changes @Nukesor? |
The predicate function now takes the current index (unchanged) and the to be added row as the context. This commit also adds two new tests, which make use of the newly passed row.
Let me know if there is anything left to add to this PR @Nukesor before merging! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice :)
I think I'm happy with the current state. Thanks for your contribution and sorry for taking so long 😅
No worries! Love to hear that! |
This PR adds the ability to only add (a) row(s) when the specified predicate evaluates to
true
. This enables a smoother "flow" when building tables. For example:With the changes introduced by this PR, we could write the above code like:
The same feature is implemented for
add_rows_if
. I also added some tests, which should cover the newly added feature.