Provide pred-only overload to std.algorithm.searching.findSkip#5577
Provide pred-only overload to std.algorithm.searching.findSkip#5577dlang-bot merged 3 commits intodlang:masterfrom
Conversation
|
Thanks for your pull request, @wilzbach! Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. |
std/algorithm/searching.d
Outdated
| bool findSkip(alias pred, R1)(ref R1 haystack) | ||
| if (isForwardRange!R1 && is(typeof(unaryFun!pred(haystack.front)))) | ||
| { | ||
| return skipOver!(pred, R1)(haystack); |
There was a problem hiding this comment.
We certainly do, as seems like that idea has been pre-approved.
47ba808 to
82dffd5
Compare
std/algorithm/searching.d
Outdated
| bool findSkip(alias pred, R1)(ref R1 haystack) | ||
| if (isForwardRange!R1 && is(typeof(unaryFun!pred(haystack.front)))) | ||
| { | ||
| return skipOver!(pred, R1)(haystack); |
There was a problem hiding this comment.
We certainly do, as seems like that idea has been pre-approved.
std/algorithm/searching.d
Outdated
| * the first occurrence of $(D needle); otherwise $(D false), | ||
| * leaving $(D haystack) untouched. | ||
| */ | ||
| bool findSkip(alias pred, R1)(ref R1 haystack) |
There was a problem hiding this comment.
Would be nice if this could return a size_t instead of just a bool.
There was a problem hiding this comment.
Sure, I just would like to wait for @andralex's opinion on this matter before investing more work.
82dffd5 to
c1c2df6
Compare
Ah - it was really trivial, so I added support for returning |
| * | ||
| * Returns: The number of times `pred` was truthfully evaluated. | ||
| */ | ||
| size_t findSkip(alias pred, R1)(ref R1 haystack) |
| { | ||
| haystack.popFront(); | ||
| c++; | ||
| } |
There was a problem hiding this comment.
Why not a loop with initial test? No need to duplicate the test in the prelude.
size_t result;
while (!haystack.empty && unaryFun!pred(haystack.front))
{
++result;
}
return result;|
I'm OK with the addition. |
|
Ping @wilzbach |
c1c2df6 to
42236b7
Compare
|
@JackStouffer @ZombineDev I finally got around rebasing this PR. It should be ready now (: |
std/algorithm/searching.d
Outdated
|
|
||
| /** | ||
| * Advances the `haystack` as long as `pred` evaluates to `true`. | ||
| * The `haystack` is positioned before position of first falsely evaluation of `pred`. |
There was a problem hiding this comment.
The haystack is positioned so as pred evaluates to false for haystack.front.
As I pointed out in #5497 (comment),
findSkipis very similar toskipOver- in fact before #5497 neitherskipOvernorfindSkiphas apred-only overload.My point is that there's no argument to add this overload to
skipOverand not tofindSkip- on the contrary there's a even a case for onlyfindSkipthat @CyberShadow pointed out:findSkipintuitively implies that it loops.